title: Pivoting rows to columns in Oracle 10g
body: <p>I've some query, that returns following data:</p>
  
  <pre><code>T_REF   T_CUR_CODE   T_TERM   T_TERM_MAX   T_REST1   T_RATE1   T_REST2   T_RATE2   T_REST3    T_RATE3
  
  1       RUR          181      365          5000      10,8      50000,01  11,1      500000,01  11,2
  1       RUR          366      730          5000      11,4      50000,01  11,55     500000,01  11,6
  1       USD          181      365          100       5,9       1500,01   6,1       20000,01   6,55
  1       EUR          181      365          100       5,7       1500,01   5,9       20000,01   6
  1       USD          366      730          100       6,3       1500,01   6,4       20000,01   6,6
  1       EUR          366      730          100       6,05      1500,01   6,2       20000,01   6,3
  </code></pre>
  
  <p>So as you can see, this query describes rates for refence. Each rate is dependent on the amount (t_rest) and duration (t_term and t_term_max). I need to group all rates for 1 refence and each currency (3 rows, with 6 rates):</p>
  
  <pre><code>T_REF   T_CUR_CODE   T_RATE_1   T_TERM_1   T_TERM_MAX_1   T_REST_1   T_RATE_2   T_TERM_2   T_TERM_MAX_2   T_REST_2   T_RATE_3   T_TERM_3   T_TERM_MAX_3   T_REST_3   T_RATE_4   T_TERM_4   T_TERM_MAX_4   T_REST_4   T_RATE_5   T_TERM_5   T_TERM_MAX_5   T_REST_5   T_RATE_6   T_TERM_6   T_TERM_MAX_6   T_REST_6
  
  1       RUR          10,8       181        365            5000       11,1       181        365            50000,01   11,2       181        365            500000,01  11,4       366        730            5000       11,55      366        730            50000,01   11,6       366        730            500000,01
  </code></pre>
  
  <p>I use it in stored procedure as dynamic query (dbms_sql package) and before generating query i now how much rates has each row (for this sample value is 3) and how much different terms has each currency (here the value is 2)</p>