title: oracle query select a column (where column name is unknown)
body: <p>My column name is retrieved from another query, then using that result as the column name I want to query to get the value. I have found a duplicate question <a href="https://stackoverflow.com/questions/4594151/select-a-column-where-the-column-name-is-retrieved-from-a-query">here</a> but I could not find the answer. So my code looks like this:  </p>
  
  <pre><code>DECLARE
      COL_NO NUMBER(3,0);
      COL_NAME VARCHAR2(30);
      COL_VALUE VARCHAR2(100);
  BEGIN
      COL_NO:=0;
      COL_NAME:=NULL;
      COL_VALUE:=NULL;
  
      SELECT COUNT(*) INTO COL_NO FROM user_tab_columns WHERE table_name='SALARYSLIP';
      FOR A IN 4..COL_NO LOOP
          SELECT column_name INTO COL_NAME FROM user_tab_columns WHERE column_id=A AND table_name='SALARYSLIP';
          --SELECT COL_NAME INTO COL_VALUE FROM SALARYSLIP WHERE ID=SALARYSLIP.ID;
          DBMS_OUTPUT.PUT_LINE(COL_VALUE);
      END LOOP;  
  END;  
  </code></pre>
  
  <p>The commented query is supposed to fetch the column value but is not working obviously. What should I write there? TIA.</p>