一个简单的sql语句执行结果的困惑

kaz33 2010-07-30 06:11:05
用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左外连接后结果集一个有数据一个没有数据呢??

...全文
168 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
wbin_ndsc 2010-08-13
  • 打赏
  • 举报
回复
感觉没区别,都能查到数据的
siriusraider 2010-08-02
  • 打赏
  • 举报
回复
汗。。。少看了个加号
ojuju10 2010-08-02
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 siriusraider 的回复:]
我测试的怎么没有数据呢?
我是在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 w……
[/Quote]

楼上的是自然连接,后面少了个+
siriusraider 2010-08-02
  • 打赏
  • 举报
回复
我测试的怎么没有数据呢?
我是在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的状况是怎么样的
小灰狼W 2010-08-02
  • 打赏
  • 举报
回复
从图片看你的描述反了
那就在''里加入与删除“1”反复执行几次看看吧
djvfe 2010-08-02
  • 打赏
  • 举报
回复
我觉得两个查询结果应该一样,左连与子查询结果那个表无关
华夏小卒 2010-08-02
  • 打赏
  • 举报
回复
select * from scott.bonus
这个有数据吗


感觉2个都不会有数据
kaz33 2010-08-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 duanzhi1984 的回复:]
SQL code
(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……
[/Quote]

没有贴错,我上两张图吧

minitoy 2010-08-02
  • 打赏
  • 举报
回复
不可能啊。。。
原理上说不通
kaz33 2010-08-02
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 siriusraider 的回复:]
我又去试了一下

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
---------- -------------- -----------……
[/Quote]

但是语句写的是左连接喔
zhuhuadeaa 2010-08-02
  • 打赏
  • 举报
回复
如果两个都是左连接的话,显然都是有数据的,如果按你说的一个有数据一个没数据的话,可能是一个是左连接,一个是右连接,或者全连接,这样才是可能的
siriusraider 2010-08-02
  • 打赏
  • 举报
回复
我又去试了一下

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命名没有数据的
kaz33 2010-08-02
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 js_szy 的回复:]
select * from scott.bonus
这个有数据吗


感觉2个都不会有数据
[/Quote]

bonus 表没有数据

我也觉得两个查询语句应该是一样的结果,但是结果不一样,不晓得为什么!!
duanzhi1984 2010-07-31
  • 打赏
  • 举报
回复
(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没有数据的话我想最终结果不会有数据的
cnwz 2010-07-31
  • 打赏
  • 举报
回复
测试了下,一样的,结果就是前表scott.DEPT的记录啊
xhfbx 2010-07-30
  • 打赏
  • 举报
回复
感觉不太可能
luoyoumou 2010-07-30
  • 打赏
  • 举报
回复
-- 有数据是什么样子的?没数据又是什么样子的?

17,089

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧