Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do you reference columns in a cursor that contain the same column name?

470360Jun 12 2009 — edited Jun 12 2009
Dear all

How does one reference two columns in a FOR CURSOR LOOP that contain the same column name, due to the fact they are two instances of the same table?

The answer is use an alias and make sure that the alias and cursor names are spelt the same way.

I previously put an example what is correct here because I retyped it instead of copying. However it wasn't right in my code:

What I preivously wrote here was:

For example:
.....CURSOR cur_name_list
IS
SELECT COMPARE.name "COMPARE",
       SEARCH.name "SEARCH"
FROM name_list COMPARE,
     name_list SEARCH
.......
I did try using the an alias in the cursor for loop that didn't work. It just said: PLS-00201: identifier 'REC_NAME_LIST.COMPARE' must be declared

However if I do not use an alias, it says:
PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names

If any one knows what I am doing wrong I would be grateful. I'm sure it is something very simple.

Kind regards

Tim

Edited by: user467357 on Jun 12, 2009 3:41 PM
The problem was a couple of typing errors in the names which I did not spot so I've amended the message and marked it answered.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 10 2009
Added on Jun 12 2009
4 comments
1,490 views