Oracle左右全连接总结
--建立测试数据
create table a(id number);
create table b(id number);
insert into a values(1);
insert into a values(2);
insert into a values(3);
insert into b values(1);
insert into b values(2);
insert into b values(4);
commit;
--左:
--主流数据库通用的方法
select * from a left join b on a.id=b.id;
--Oracle特有的方法
select * from a, b where a.id=b.id(+);
ID ID
---------- ----------
1 1
2 2
3
--右:
--主流数据库通用的方法
select * from a right join b on a.id=b.id;
--Oracle特有的方法
select * from a, b where a.id(+)=b.id;
ID ID
---------- ----------
1 1
2 2
4
--内
--主流数据库通用的方法
select * from a join b on a.id=b.id;
--where关联
select * from a, b where a.id=b.id;
ID ID
---------- ----------
1 1
2 2
--全外
--主流数据库通用的方法
select * from a full join b on a.id=b.id;
--Oracle特有的方法
select *
from a, b
where a.id = b.id(+)
union
select *
from a, b
where a.id(+) = b.id;
ID ID
---------- ----------
1 1
2 2
3
4
--完全,也叫交叉连接或者笛卡尔积
--主流数据库通用的方法
select * from a,b;
--或者
select * from a cross join b;
ID ID
---------- ----------
1 1
1 2
1 4
2 1
2 2
2 4
3 1
3 2
3 4
连接无非是这几个
--内连接和where相同
inner join
--左向外连接,返回左边表所有符合条件的
left join
--右向外连接,返回右边表所有符合条件的
right join
--完整外部连接,左向外连接和右向外连接的合集
full join
--交叉连接,也称笛卡儿积。返回左表中的每一行与右表中所有行的组合
cross join
--补充:
--左向外连接,返回左边表所有符合条件的,
--注意这里没有第二个加号,会直接过滤掉数据,只显示符合条件的记录
select *
from a, b
where a.id = b.id(+)
and b.id = 2;
ID ID
---------- ----------
2 2
--左向外连接,返回左边表所有符合条件的
--注意where上第二个加号,它的作用是修改右边表记录的显示,例如如果b.id(+) = 2,显示为2,否则显示null
select *
from a, b
where a.id = b.id(+)
and b.id(+) = 2;
ID ID
---------- ----------
2 2
3
1
分享到:
- 2009-09-04 14:54
- 浏览 759
- 评论(0)
- 论坛回复 / 浏览 (0 / 4603)
- 查看更多
相关推荐
oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结
oracle客户端配置连接oracle客户端配置连接oracle客户端配置连接
oracle学习心得和总结,本人看过,感觉超好
oracle修改最大连接数
oracle表连接学习总结(火) oracle表连接学习总结(火) oracle表连接学习总结(火)
oracle 左连接 右连接 学习 精选资料
JAVA 使用数据库连接池连接Oracle数据库,全代码,附加详细说明
数据库左右连接方法详细讲解,文档内列举了实例。很清晰
Oracle非常全的学习文档,免费分享给大家。内容比较丰富,适合参看
oracle客户端连接远程库的配置文件,不需要安装oracle,只需配置即可
Oracle数据库的学习总结一Oracle数据库的学习总结一
屏蔽了1521端口 Oracle远程连接数据库总结 注:本文讲述了oracle数据库实例连接的配置过程,三个重要的配置文件位于C:\oracle\product\10.1.0\Db_1\NETWORK\ADMIN目录下 1. sqlplus sys/oracle@orcl sqlnet.ora 文件...
ORACLE 数据库配置 如何连接,连接方式
Oracle最大连接数
oracle数据库表左连接右连接全连接的认识
文档中的内容是从网上资料和自己在Oracle的日常巡检中总结的Oracle日常巡检项。
查看oracle数据库的连接数以及用户 1、查询oracle的连接数 2、查询oracle的并发连接数 3、查看不同用户的连接数 4、查看所有用户: 5、查看用户或角色系统权限(直接赋值给用户或角色的系统权限): 6、...
Oracle-新建Oracle数据库并连接(图文,详细).docx
Oracle连接类Oracle连接类Oracle连接类Oracle连接类Oracle连接类
python-oracledb的源码和使用示例代码, python-oracledb 1.0,适用于Python versions 3.6 through 3.10. Oracle Database; This directory contains samples for python-oracledb. 1. The schemas and SQL ...