Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Transposing rows into columns

RaghavendraNaraFeb 20 2020 — edited Feb 20 2020

Hi All,

Could you please assist me any one here on transposing rows into columns ?

I have below table structure.

CREATE TABLE TEST_TRANSPOSE(APPROVAL_LEVEL NUMBER,ITEM VARCHAR2(10),Approver1 VARCHAR2(50),Approver2 VARCHAR2(50), Approver3 VARCHAR2(50));

INSERT INTO TEST_TRANSPOSE VALUES (1,'A','ABC','DEF','XYZ');

INSERT INTO TEST_TRANSPOSE VALUES (2,'A','KBC','LEF','MYZ');

INSERT INTO TEST_TRANSPOSE VALUES (3,'A','NBC','OEF','PYZ');

INSERT INTO TEST_TRANSPOSE VALUES (4,'A','QBC','REF','SYZ');

INSERT INTO TEST_TRANSPOSE VALUES (5,'A','TBC','UEF','VYZ');

COMMIT;

SELECT * FROM TEST_TRANSPOSE;

pastedImage_2.png

The expected is for every approval_level we have three approvers so we need to display three row for every row with respect to approval_level.

Expected is as below -

APPROVAL_LEVEL ITEM Approver_Name

------------- ----- -------------

1 A ABC

1 A DEF

1 A XYZ

2 A KBC

2 A LEF

2 A MYZ

3 A NBC

3 A OEF

3 A PYZ

4 A QBC

4 A REF

4 A SYZ

5 A TBC

5 A UEF

5 A VYZ

Regards

Raghav

This post has been answered by mNem on Feb 20 2020
Jump to Answer
Comments
Post Details
Added on Feb 20 2020
2 comments
164 views