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!

pivot multiple rows (at most 3) into columns

Gor_MahiaAug 21 2022

All,
iam using the emp table to fetch the next 2 upper level supervisors (if available) for a given employee as show below

 SELECT ename, empno, mgr, job, LEVEL   

FROM emp
START WITH empno = 7900 -- example 7698 passed as parameter
CONNECT BY empno = PRIOR mgr
AND LEVEL <= 3

now iam trying to transform all the rows returned ( at most 3 ) into columns to have only one record as below:
emp_name || supervisor1_name|| supervisor2_name|| empno1|| empno2|| empno3

JAMES BLAKE KING 7900 7698 7839

i think i should use the pivot but it didnt work for me - any help please?
Oracle 12 g

thanks.

This post has been answered by mathguy on Aug 21 2022
Jump to Answer
Comments
Post Details
Added on Aug 21 2022
8 comments
996 views