Home > database > How to query a field according to a certain character to group
How to query a field according to a certain character to group
Time:10-01
Such as: such as query test t content of this field in the table is T -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- A, B, C, D How can the results of a query for T -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- A B C D
CodePudding user response:
- support multiple lines
SQL> SQL> Create table test (int id, name varchar (50)); The Table created SQL> The begin 2 insert into the test values (1, 'A, B, C, D, E, F'); 3 the insert into the test values (2, '111333555,'); 4 the end; 5/ PL/SQL procedure successfully completed SQL> A10 col id format; SQL> Select id, regexp_substr (name, '[^,] +', 1, level) colA 2 the from test 3 connect by level & lt;=regexp_count (name, ', ') + 1 4 and the prior rowid=rowid 5 and the prior dbms_random. The value is not null 6 the order by id, cola; ID COLA -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1 A 1 B 1 C 1 D 1 E 1 F 2 111 2 22 2 333 2 555 10 rows selected SQL> Drop table test purge; Table dropped
SQL>
CodePudding user response:
If without a primary key id to separate queries to group name value also can be, but the efficiency is very slow,