oracle的SQL语句中的(+)是干什么用的?

如题所述

这个(+)是数据连接的意思,用于表外链接,外链接
举例:
select a.ENAME,b.ENAME from emp a,emp b where a.MGR=b.empno(+);--外连接 内表或俩表比较有+端强制显示空结果
select a.ENAME as ben,b.ENAME as shangji from emp a,emp b where a.MGR=b.empno(+) and a.hiredate<b.hiredate;
select a.dname,b.* from dept a,emp b where a.deptno=b.deptno(+) order by b.empno;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-09-19
oracle特有的左外联书写方式,当然你也可以用传统的通用的左外联,比如给你举个例子
SELECT s.name AS 姓名,g.grade AS 分数,c.cid AS 课程名
FROM tbl_student s LEFT OUTER JOIN tbl_grade g ON s.StudentId=g.sid LEFT OUTER JOIN tbl_class c ON g.cid=c.ClassId
它跟下面等价
SELECT s.name AS 姓名,g.grade AS 分数,c.classname AS 课程名
FROM tbl_student s,tbl_grade g,tbl_class c
WHERE (s.StudentId=g.sid(+)) AND (g.cid=c.ClassId(+))本回答被提问者和网友采纳
第2个回答  2010-09-19
外连接的意思。
请参考原厂手册中的说明:

Outer Joins
An outer join extends the result of a simple join. An outer join returns all rows that satisfy the join condition and also returns some or all of those rows from one table for which no rows from the other satisfy the join condition.

1、To write a query that performs an outer join of tables A and B and returns all rows from A (a left outer join), use the LEFT [OUTER] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of B in the join condition in the WHERE clause. For all rows in A that have no matching rows in B, Oracle Database returns null for any select list expressions containing columns of B.

2、To write a query that performs an outer join of tables A and B and returns all rows from B (a right outer join), use the RIGHT [OUTER] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of A in the join condition in the WHERE clause. For all rows in B that have no matching rows in A, Oracle returns null for any select list expressions containing columns of A.

3、To write a query that performs an outer join and returns all rows from A and B, extended with nulls if they do not satisfy the join condition (a full outer join), use the FULL [OUTER] JOIN syntax in the FROM clause.