[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Referncing Columns In a Cursor By Index

Posted on 2009-07-15
5
Medium Priority
?
549 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 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

649 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