用scott登录oracl,dept表有4条数据:
1 10 ACCOUNTING NEW YORK
2 20 RESEARCH DALLAS
3 30 SALES CHICAGO
4 40 OPERATIONS BOSTON
bonus表没有数据执行下面两个sql语句:
(1)select * from scott.DEPT t , (select * from scott.bonus where job = '') a where t.dname = a.ename(+)
(2)select * from scott.DEPT t , (select * from scott.bonus where job = '1') a where t.dname = a.ename(+)
语句(1)有数据,(2)没有数据我的疑惑: 
(1)bonus表没数据,job=‘1’和job=‘’对于select * from scott.bonus来说是一样的结果,为什么和dept左外连接后结果集一个有数据一个没有数据呢??

解决方案 »

  1.   

    测试了下,一样的,结果就是前表scott.DEPT的记录啊
      

  2.   

    (1)select * from scott.DEPT t , (select * from scott.bonus where job = '') a where t.dname = a.ename(+)
    (2)select * from scott.DEPT t , (select * from scott.bonus where job = '1') a where t.dname = a.ename(+)
    语句(1)有数据,(2)没有数据哥们,你的语句肯定贴错了吧!是不是一个是左连接,一个是全连接呢?上面的语句若bonus没有数据的话我想最终结果不会有数据的
      

  3.   

    select * from scott.bonus 
    这个有数据吗
    感觉2个都不会有数据
      

  4.   

    我测试的怎么没有数据呢?
    我是在scott下面试的oracle 11g,windows xp
    SQL> select * from dept t,(select * from bonus where job='') a where t.dname=a.e
    name;未选定行SQL> select * from dept t,(select * from bonus where job='1') a where t.dname=a.
    ename;未选定行这是我复制下来的,贴图好麻烦,不知道LZ的状况是怎么样的
      

  5.   


    bonus 表没有数据我也觉得两个查询语句应该是一样的结果,但是结果不一样,不晓得为什么!!
      

  6.   

    我又去试了一下SQL> select * from scott.DEPT t , (select * from scott.bonus where job = '') a w
    here t.dname = a.ename(+)
      2  ;    DEPTNO DNAME          LOC           ENAME      JOB              SAL
    ---------- -------------- ------------- ---------- --------- ----------
          COMM
    ----------
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            10 ACCOUNTING     NEW YORK    DEPTNO DNAME          LOC           ENAME      JOB              SAL
    ---------- -------------- ------------- ---------- --------- ----------
          COMM
    ----------
            40 OPERATIONS     BOSTON已用时间:  00: 00: 00.03
    SQL> select * from scott.DEPT t , (select * from scott.bonus where job = '1') a
    where t.dname = a.ename(+)
      2  ;    DEPTNO DNAME          LOC           ENAME      JOB              SAL
    ---------- -------------- ------------- ---------- --------- ----------
          COMM
    ----------
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            10 ACCOUNTING     NEW YORK    DEPTNO DNAME          LOC           ENAME      JOB              SAL
    ---------- -------------- ------------- ---------- --------- ----------
          COMM
    ----------
            40 OPERATIONS     BOSTON已用时间:  00: 00: 00.01是这个意思么?我是新手,大家见谅,我也奇怪bonus命名没有数据的