使用加号(+)转换Oracle的连接语法到标准连接语法

zig*_*ggy 2 sql oracle oracle10g oracle11g

我试图理解使用(+)连接两个表的Oracle连接语法.有人可以告诉我,如果它被转换为使用标准连接语法,这个查询将会是什么样子?

select p1.product_id, p1.product_name, p2.product_code, (decode(p3.product_type, null, 'N/A',p3.product_type) as product_type
from products p1, product_descriptions p2, product_descriptions p3
where p1.product_id=p2.product_id
and p2.product_age=p3.product_age(+)
and p2.product_type=p3.product_type(+)
and p3.status(+)='VALID'
Run Code Online (Sandbox Code Playgroud)

Ale*_*ole 5

像这样的东西:

select p1.product_id, p1.product_name, p2.product_code,
    (decode(p3.product_type, null, 'N/A', p3.product_type) as product_type
from products p1
join product_descriptions p2
    on p1.product_id = p2.product_id
left join product_descriptions p3
    on p3.product_age = p2.product_age
    and p3.product_type = p2.product_type
    and p3.status = 'VALID';
Run Code Online (Sandbox Code Playgroud)

where p1.product_id=p2.product_idp1和之间的正常内连接p2.其他是外连接; 它的编写方式看起来像是左右外连接的混合,但由于它是and p2.product_age=p3.product_age(+)相同的,and p3.product_age(+)=p2.product_age它不是真的; 它是p1/ p2join和/ 的产品之间相当简单的左外连接p3.

顺便说一句,我不喜欢的别名的粉丝p1,p2并且p3因为它们不是描述性的,而且很容易迷路,当你这样做的更复杂的查询.我并不孤单.

我不确定你甚至需要外连接,但它取决于数据.如果product_age并且product_type是独特的那么你就可以casep2.status; 如果不是那么你可能假设只有一个product_age/ product_typeVALID,否则你会得到重复.只是思考你想要做的事......