Solved

Referncing Columns In a Cursor By Index

Posted on 2009-07-15
5
546 Views
Last Modified: 2013-12-07
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;
0
Comment
Question by:ccovell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 48

Expert Comment

by:schwertner
ID: 24861676

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;
0
 

Author Comment

by:ccovell
ID: 24861730
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.
0
 
LVL 20

Accepted Solution

by:
flow01 earned 250 total points
ID: 24861846
Using same alias everywhere in the union is neat programming .
Until know however (in my experience) you can reference the columns of the union by the columns_names of the first union part.
0
 
LVL 48

Assisted Solution

by:schwertner
schwertner earned 250 total points
ID: 24862188
In UNION query the column names of the first query are used in the set statement. Also aliases could be given.
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question