Converting rows to columns in ORACLE SQL with parametrization -
for 1 of etl-jobs need sql-query converts rows columns. difficulty want parameterize how many rows getting converted 1 column shown in following example:
atm scenario looks this:
oracle 11g
one column table:
parameter
ab
ae
cf
gh
5g
h3
7p
…..
sql-query:
select listagg ('''' ||parameter ||'''', ',') within group ( order rownumber) parameter, (select case when rownum <= 5 5 when rownum <= 10 10 when rownum <= 15 15 when rownum <= 20 20 when rownum <= 25 25 end rownumber parameter sr0_crtl_sl_ol_psm_parameter ) group rownumber
result this:
parameter
ab, bg, rt, zh, jk
ae, hl, gh, dz, kl
cf, gh, nm, sd, …..
what have query takes number eg. 5 following result:
parameter
ab, bg, rt, zh, jk
ae, hl, gh, dz, kl
cf, gh, nm, sd, …..
or takes eg. 8 , result like:
parameter
ab, bg, rt, zh, jk, ae, hl, gh
dz, kl, cf, gh, nm, sd, we, de
fg, jk, kl, uz, it, fg, hr, tz …..
i hope mean. maybe provide me help.
thanks
ps: know english damn “: }
you can calculate group using arithmetic -- division , take integer it. following uses "8" parameter:
select listagg (''''||parameter||'''', ',') within group (order rownumber) parameter, (select trunc((rownum - 1) / 8) grp, t.*, rownum rownumber sr0_crtl_sl_ol_psm_parameter t ) t group grp;
Comments
Post a Comment