Dynamic pivot in oracle sql -


... pivot (sum(a) b in (x))

now b of datatype varchar2 , x string of varchar2 values separated commas.
values x select distinct values column(say cl) of same table. way pivot query working.

but problem whenever there new value in column cl have manually add string x.

i tried replacing x select distinct values cl. query not running.
reason felt due fact replacing x need values separated commas.
created function return exact output match string x. query still doesn't run.
error messages shown "missing righr parantheses", "end of file communication channel" etc etc.
tried pivot xml instead of pivot, query runs gives vlaues oraxxx etc no values @ all.

maybe not using properly.
can tell me method create pivot dynamic values?

you can't put non constant string in in clause of pivot clause.
can use pivot xml that.

from documentation:

subquery subquery used in conjunction xml keyword. when specify subquery, values found subquery used pivoting

it should this:

select xmlserialize(content t.b_xml) t_aa pivot xml( sum(a) b in(any) ) t; 

you can have subquery instead of any keyword:

select xmlserialize(content t.b_xml) t_aa pivot xml( sum(a) b in (select cl t_bb) ) t; 

here sqlfiddle demo


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -