sql - How do I return multiple column values as new rows in Oracle 10g? -
i have table multiple account numbers associated different ids(dr_name). each account have few 0 accounts, , many 16. believe unpivot work, i'm on oracle 10g, not support this.
dr_name acct1 acct2 acct3 acc4 ====================================== smith 1234 jones 5678 2541 2547 mark null ward 8754 6547
i want display new line each name 1 account number per line
dr_name acct ============== smith 1234 jones 5678 jones 2541 jones 2547 mark null ward 8754 ward 6547
oracle 10g not have unpivot
function can use union all
query unpivot columns rows:
select t1.dr_name, d.acct yourtable t1 left join ( select dr_name, acct1 acct yourtable acct1 not null union select dr_name, acct2 acct yourtable acct2 not null union select dr_name, acct3 acct yourtable acct3 not null union select dr_name, acct4 acct yourtable acct4 not null ) d on t1.dr_name = d.dr_name;
see sql fiddle demo.
this query uses union all
convert columns rows. included where
clause remove null
values, otherwise multiple rows each account acct value null. excluding null
values drop dr_name = mark
showed want in final result. include rows have null
values, added join table again.
Comments
Post a Comment