Link to home
Start Free TrialLog in
Avatar of ccovell
ccovellFlag for United States of America

asked on

Referncing Columns In a Cursor By Index

Is there a way to reference columns in a cursor by index rather than by column name?  For instance,

DECLARE
  CURSOR myCursor IS
  SELECT first_name,
    last_name
  FROM customer;
BEGIN
  FOR curRecord IN myCursor LOOP
    DBMS_OUTPUT.PUT_LINE(curRecord(1));
    DBMS_OUTPUT.PUT_LINE(curRecord(2));
  END LOOP;
END;
Avatar of schwertner
schwertner
Flag of Antarctica image


So far only this can work

DECLARE
  CURSOR myCursor IS
  SELECT first_name,
    last_name
  FROM employees;
BEGIN
  FOR curRecord IN myCursor LOOP
    DBMS_OUTPUT.PUT_LINE(curRecord.first_name));
    DBMS_OUTPUT.PUT_LINE(curRecord.last_name));
  END LOOP;
END;
Avatar of ccovell

ASKER

ty schwertner,
I've come to the conclusion that this functionality is definitely no available.  Kind sad if your in a situation like me where you have a multi union query and there is no consistent name for the same column in each of the union components.  I've resided to giving them all the same alias and just using the alias reference in the cursor.
ASKER CERTIFIED SOLUTION
Avatar of flow01
flow01
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial