开发者

Using %rowtype with a join and duplicate columns

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 valu开发者_运维技巧e columns?


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;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜