title: Oracle select column names dynamically from another table
body: <p>I have two tables. Lets say <strong>tab1</strong> and <strong>tab2</strong>.</p>
  <p><strong>tab1</strong> has data like this:</p>
  <p><kbd><strong><code>ID        </code></strong></kbd><kbd><strong><code>Field Name</code></strong></kbd><br/>
  <kbd><code>00001     </code></kbd><kbd><code>col1      </code></kbd><br/>
  <kbd><code>00001     </code></kbd><kbd><code>col63     </code></kbd><br/>
  <kbd><code>00002     </code></kbd><kbd><code>col3      </code></kbd><br/>
  <kbd><code>00002     </code></kbd><kbd><code>col47     </code></kbd><br/>
  <kbd><code>00003     </code></kbd><kbd><code>col22     </code></kbd><br/>
  <kbd><code>00003     </code></kbd><kbd><code>col40     </code></kbd><br/></p>
  <p>Each <strong>ID</strong> has always <strong>2 Field Name</strong> values.</p>
  <p>And <strong>tab2</strong> has columns <strong>col1</strong>,<strong>col2</strong>,<strong>col3</strong>,<strong>col4</strong>....<strong>col70</strong></p>
  <p>I want to select columns dynamically from tab2.</p>
  <p>Like for <strong>00001</strong> it should be:</p>
  <pre><code>select col1,col63 from tab2;
  </code></pre>
  <p>Similarly for <strong>00002</strong> it should be :</p>
  <pre><code>select col3,col47 from tab2;
  </code></pre>
  <blockquote>
  <p>Is there any way to achieve this without using function or procedure ? I am using Oracle 11G.</p>
  </blockquote>