title: SQL: Dynamic renaming of columns based on row values
body: <p>Considering <code>Oracle 10g</code>, is there a way to rename a column based on specified rows?</p>
  
  <p>Let me first give a background. The requirement was to pivot rows and turn them to columns. Since Oracle 10g doesn't support the function PIVOT, we've done a work around using <code>max and case</code> keywords. </p>
  
  <p>Now the problem is this. Is there a way to rename a column based on two rows?
  Considering the tables below:</p>
  
  <pre><code>BRAND   | MODEL  | COMPONENT_NAME | COMPONENT_VALUE | ATTRIBUTE_NAME | ATTRIBUTE_VALUE
  -----------------------------------------------------------------------------------
  SAMSUNG | I9100  | Chipset        | Exynos          | frequency      | 1200     
  SAMSUNG | I9100  | Screen         | Amoled          | colors         | 16M  
  SAMSUNG | I9100G | Chipset        | TI OMAP4430     | frequency      | 1200     
  SAMSUNG | I9100G | Screen         | Amoled          | colors         | 16M 
  ------------------------------------------------------------------------------------
  </code></pre>
  
  <p>We want this: with the <code>COMPONENT_NAME</code> above transformed as the <code>`column header for one and the</code>COMPONENT_NAME - ATTRIBUTE_NAME` as for another.</p>
  
  <pre><code>BRAND   | MODEL  | Chipset     | Chipset - frequency | Screen | Screen - colors
  ------------------------------------------------------------------------
  SAMSUNG | I9100  | Exynos      | 1200                | Amoled | 16M        
  SAMSUNG | I9100G | TI OMAP4430 | 1200                | Amoled | 16M
  ------------------------------------------------------------------------
  </code></pre>
  
  <p>currently we do the following to produce the second table:</p>
  
  <pre><code>SELECT DISTINCT BRAND, MODEL,
  MAX(CASE WHEN (COMPONENT_NAME = 'Chipset') THEN
  COMPONENT_VALUE
  END) AS "Chipset",
  MAX(CASE WHEN (COMPONENT_NAME = 'Chipset' and ATTRIBUTE_NAME = 'frequency') THEN
  ATTRIBUTE_VALUE
  END) AS "Screen",
  MAX(CASE WHEN (COMPONENT_NAME = 'Screen') THEN
  COMPONENT_VALUE
  END) AS "Screen",
  MAX(CASE WHEN (COMPONENT_NAME = 'Screen' and ATTRIBUTE_NAME = 'colors') THEN
  ATTRIBUTE_VALUE
  END) AS "Screen - colors" from table....etc.
  </code></pre>
  
  <p>Is there a way to dynamically name the column?</p>