• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Oracle 左连接(+)加号用法及常用语法之间的关系

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文目的:

通过分析左连接(+)加号的写法和一些常用语法之间的联系,了解到Oracle 加号(+)的用法

分析步骤:

1.首先创建测试表的结构:

create table test_left_a (
a varchar2(50),
b varchar2(50)
)
create table test_left_b (
a varchar2(50),
b varchar2(50)
)

2.插入相应的测试数据:

insert into test_left_a select 'a','21' from dual;
commit;
insert into test_left_a select 'c','2111' from dual;
commit;

insert into test_left_b select 'a','12' from dual;
commit;
insert into test_left_b select 'b','13' from dual;
commit;

3.列举出实现左连接查询的几种常用的语法,以便对比分析

实现左连接查询(不加where)的几种语法:

A:

select * from test_left_a a left join test_left_b b on a.a = b.a;

B:

select * from test_left_a a, test_left_b b where a.a = b.a(+);

C:

select *
from test_left_a a
inner join test_left_b b on a.a = b.a(+);

实现左连接查询(加where)的几种语法:

D:

select *
from test_left_a a
left join test_left_b b on a.a = b.a
where a.a = b.a;

E:

select *
from test_left_a a, test_left_b b
where a.a = b.a(+)
and a.a = b.a;

F:

select *
from test_left_a a
inner join test_left_b b on a.a = b.a(+)
and a.a = b.a;

G:

select *
from test_left_a a
inner join test_left_b b on a.a = b.a(+)
where a.a = b.a;

区分where的目的是为了由浅入深,避免在理解类似E写法的时候出现on的误导引起偏差

4.结论:

以上几种查询(暂不考虑性能,只考虑用法)
A等价于B等价于C
查询结果:
a 21 a 12
c 2111
D等价于E等价于F等价于G
查询结果:
a 21 a 12

5.温馨提示:

使用inner join的时候 直接在on后面写条件和在where后再写条件是一样的,原因是内连接是匹配出on条件为真的记录(参考F和G)。

使用left join或者right join的时候,直接在on后面写条件和在where后再写条件是不一样的,原因是:

  left join即使on后面的条件为假也会显示出左表的所有记录

  right join即使on后面的条件为假也会显示出右表的所有记录。

总结

以上所述是小编给大家介绍的Oracle 左连接(+)加号用法及常用语法之间的关系 ,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对极客世界网站的支持!


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
SQL中EXPLAIN命令的使用方法发布时间:2022-02-08
下一篇:
MySQL查询优化必备知识点总结发布时间:2022-02-08
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap