views:

118

answers:

2

Given (ignore the lack of primary keys, foreign keys, etc - this isn't about table design and is just an example):

Order:
----------
ID NUMBER;
VENDOR NUMBER;
PART NUMBER;

Parts:
------------
ID NUMBER;
VENDOR NUMBER;
DESCRIPTION VARCHAR2(1000 CHAR);


cursor c1 is select * from order o left join parts p on o.part = p.id;
c_row c1%rowtype;

How do I distinguish between the two VENDOR columns that will be in the join?

I don't think I can do c_row.value because that would be ambiguous, and I don't think something like c_row.p.vendor works.

How can I refer to a particular instance of the two value columns?

A: 
cursor c1 is select * from order o left join
(select id parts_id, vendor parts_vendor,
    description parts_description from parts) p
on o.part = p.parts_id;
c_row c1%rowtype;

And you'll have vendor and parts_vendor.

Khb
+5  A: 

I generally avoid SELECT * because it makes the code vulnerable to unrelated changes to the table structure.

cursor c1 is
select o.id, o.vendor AS order_vendor, o.part,
       p.vendor AS part_vendor, p.description
from order o left join parts p on o.part = p.id;
Jeffrey Kemp