How to convert one row to multiple rows in ORACLE

Source: Internet
Author: User


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.