SQL> select empno,dept.deptno,dname
  2  from emp,dept
  3  where emp.deptno(+)=dept.deptno and emp.deptno(+)=10;     EMPNO     DEPTNO DNAME
---------- ---------- --------------
      7782         10 ACCOUNTING
      7934         10 ACCOUNTING
      7839         10 ACCOUNTING
                   20 RESEARCH
                   30 SALES
                   40 OPERATIONS已选择6行。  1  select empno,emp.deptno,dname
  2  from emp,dept
  3* where emp.deptno(+)=dept.deptno and emp.deptno(+)=10
SQL> /     EMPNO     DEPTNO DNAME
---------- ---------- --------------
      7782         10 ACCOUNTING
      7934         10 ACCOUNTING
      7839         10 ACCOUNTING
                      RESEARCH
                      SALES
                      OPERATIONS已选择6行。
两个都是右连接,唯一的不同是上面查询语句是“dept.deptno”,而下面是“emp.deptno”。造成结果中deptno显示的不同。出现结果的原因是什么?

解决方案 »

  1.   

    前一个select,选择的是emp中的deptno,自然之友10了
    后一个select选择的dept中的deptno,由于是右链接,自然会显示其他的deptno值
      

  2.   

    你改成select * from ...把全部列显示出来,就知道了。
      

  3.   

    emp.deptno(+)=10
    这个已经把emp.deptno的只保留了10部门的了,
    emp.deptno(+)=dept.deptno
    这个右外链,保留了deptno所有部件的编号,
      

  4.   

    <code=sql>
    select empno,emp.deptno,dname
    </code>
    表示从emp表中选择部门,而条件已经将非10部门的部门给过滤掉了,所以只要10部门了。