title: Dynamic Pivot in Oracle's SQL
body: <p>... pivot (sum(A) for B in (X))  </p>
  
  <p>Now B is of datatype varchar2 and X is a string of varchar2 values separated by commas.<br>
  Values for X are select distinct values from a column(say CL) of same table. This way pivot query was working.  </p>
  
  <p>But the problem is that whenever  there is a new value in column CL I have to manually add that to the string X.</p>
  
  <p>I tried replacing X with select distinct values from CL. But query is not running.<br>
  The reason I felt was due to the fact that for replacing X we need values separated by commas.<br>
  Then i created a function to return exact output to match with string X. But query still doesn't run.<br>
  The error messages shown are like "missing righr parantheses", "end of file communication channel" etc etc.<br>
  I tried pivot xml instead of just pivot, the query runs but gives vlaues like oraxxx etc which are no values at all. </p>
  
  <p>Maybe I am not using it properly.<br>
  Can you tell me some method to create a pivot with dynamic values?</p>