The ORACLE line to multi-row problem/** the core solution is to generate a column from 1 to 10, as A "secondary column" **/select level l FROM dual connect by level <= 10; [problem] Two tables a ba table: www.2cto.com id pidA1 1A2 2A3 3 B table: pid pnumber1 22 33 5 according to the number of Pnumber generated such information id list A1 A1-1A1 A1-2A2 A1-1A2 A1-2A2 A1-3A3 A1-1A3 A1-2A3 A1-3A3
/** Create a test TABLE T1, that is, table a mentioned by the landlord **/create table t1 (www.2cto.com ID VARCHAR2 (10), pid VARCHAR2 (10 )); /** CREATE the test TABLE T2, that is, the B TABLE mentioned by the landlord **/CREATE TABLE t2 (pid VARCHAR2 (10), pnumber VARCHAR2 (10 )); /** INSERT T1 data and T2 test data **/insert into t1 VALUES ('a1', '1'); insert into t1 VALUES ('a2 ', '2'); insert into t1 VALUES ('a3 ', '3'); insert into t2 VALUES ('1', '2 '); insert into t2 VALUES ('2', '3'); insert into t2 VALUES ('3', '5'); the core solution of www.2cto.com/** is: generate a column FROM 1 to 10 as the "secondary column" **/select level l FROM dual connect by level <= 10;/** final SQL **/SELECT T1.ID, 'a1-'| T3.DZ as list from T1, T2, (select level dz from dual connect by level <= 10) t3 WHERE T1.PID = T2.PID AND T3.DZ <= T2.PNUMBER order by 1, 2; prepared BY ziwen00