1 Reply Latest reply: Feb 18, 2011 10:17 AM by gdarling - oracle RSS

    can we use positon of a column for data fetching

    807875
      Hi I want to calculate a value from a table based on the position of a column
      suppose user passes 1 then value in column 1 is fetched if 2 then 2 is fetched with row condition known.
        • 1. Re: can we use positon of a column for data fetching
          gdarling - oracle
          What are you using for DataAccess?

          I'm not sure what you're asking. Are you saying you want to retrieve data from only the Nth column of a table (as opposed to something like +recset.fields[n].value+) and you just want to know how to determine what the name of the Nth column is so you can use it in your query?
          select column_name from user_tab_columns where table_name='<TABLENAME>' order by column_id
          should get you that.

          Hope it helps,
          Greg
          SQL> select column_name from user_tab_columns where table_name='EMP' order by column_id;
          
          COLUMN_NAME
          ------------------------------
          EMPNO
          ENAME
          JOB
          MGR
          HIREDATE
          SAL
          COMM
          DEPTNO
          
          8 rows selected.
          
          SQL> desc emp;
           Name                                      Null?    Type
           ----------------------------------------- -------- ----------------------------
           EMPNO                                     NOT NULL NUMBER(4)
           ENAME                                              VARCHAR2(10)
           JOB                                                VARCHAR2(9)
           MGR                                                NUMBER(4)
           HIREDATE                                           DATE
           SAL                                                NUMBER(7,2)
           COMM                                               NUMBER(7,2)
           DEPTNO                                             NUMBER(2)
          
          SQL>