您的位置:首页 > 数据库 > Oracle

ORACLE连接类型 各种连接查询PL/SQL测试

2008-09-29 12:24 357 查看
---测试ORACLE 所有连接类型 PL/SQL 中执行的
--本人初学,可能有理解不到位的地方,请指正,谢谢!
--建表
create table xxaa (id number(10),name varchar2(20));

create table xxbb (idd number(10),namee varchar2(20));

--INSERT 数据,或者 FOR UPDATE 也可以
select * from xxaa for update;
select * from xxbb for update;

/* 表A 数据
1 1 a
2 2 b
3 3 c
4 4 d
5 e
6 f
*/
/* 表B数据
1 1 e
2 2 f
3 3 g
4 4 h
5 5 i
6 6 j
7 7 k
8 8 l
9 9
*/

---测试ORACLE 所有连接类型 PL/SQL 中执行的

--本人初学,可能有理解不到位的地方,请指正,谢谢!

--建表

create table xxaa (id number(10),name varchar2(20));

create table xxbb (idd number(10),namee varchar2(20));

--INSERT 数据,或者 FOR UPDATE 也可以

select * from xxaa for update;

select * from xxbb for update;

/* 表A 数据

1 1 a

2 2 b

3 3 c

4 4 d

5 e

6 f

*/

/* 表B数据

1 1 e

2 2 f

3 3 g

4 4 h

5 5 i

6 6 j

7 7 k

8 8 l

9 9

*/

select * from xxaa a,xxbb b where a.id(+)=b.idd;--右连接,以B表为基表,匹配B表中的都输出

select * from xxaa a,xxbb b where a.id=b.idd(+); --左连接,以A表为基表,匹配A表的都输出 相当于left join 和left outer Join

select * from xxaa a,xxbb b where a.id=b.idd; -- =连接 A,B表都匹配才输出

select * from xxaa a left join xxbb b on (a.id=b.idd); --左内连

select * from xxaa a right join xxbb b on (a.id=b.idd); --右内连

select * from xxaa a full join xxbb b on (a.id=b.idd); --完全连接 --A表和B表的 并集

select * from xxaa a inner join xxbb b on (a.id=b.idd); --内连接 --A表和B表的 交集

select * from xxaa a left outer join xxbb b on (a.id=b.idd);--左外连

select * from xxaa a right outer join xxbb b on (a.id=b.idd); --右外连

select * from xxaa a full outer join xxbb b on (a.id=b.idd); --完全外联

select * from xxaa a join xxbb b on (a.id=b.idd); --相当于= 连接

select * from xxaa a,xxbb b where a.id(+)=b.idd;--右连接,以B表为基表,匹配B表中的都输出
select * from xxaa a,xxbb b where a.id=b.idd(+); --左连接,以A表为基表,匹配A表的都输出 相当于left join 和left outer Join
select * from xxaa a,xxbb b where a.id=b.idd; -- =连接 A,B表都匹配才输出
select * from xxaa a left join xxbb b on (a.id=b.idd); --左内连
select * from xxaa a right join xxbb b on (a.id=b.idd); --右内连
select * from xxaa a full join xxbb b on (a.id=b.idd); --完全连接 --A表和B表的 并集
select * from xxaa a inner join xxbb b on (a.id=b.idd); --内连接 --A表和B表的 交集
select * from xxaa a left outer join xxbb b on (a.id=b.idd);--左外连
select * from xxaa a right outer join xxbb b on (a.id=b.idd); --右外连
select * from xxaa a full outer join xxbb b on (a.id=b.idd); --完全外联
select * from xxaa a join xxbb b on (a.id=b.idd); --相当于= 连接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: