困惑于“或” oracle中的条件子句?
这是我工作中遇到的问题,我简化如下: 首先是测试用例
create table A_TESTB
(
A VARCHAR2(10),
B VARCHAR2(10)
);
insert into A_TESTB (A, B)
values ('1', '2');
insert into A_TESTB (A, B)
values ('1', '3');
insert into A_TESTB (A, B)
values ('1', '4');
commit;
SQL> select * from a_testb;
A B
---------- ----------
1 2
1 3
1 4
,我使用如下sql
SQL> SELECT *
2 FROM (SELECT '10' TESTTYPE, T.* FROM A_TESTB T) W
3 WHERE (W.A = '1' OR 1 = 2)
4 AND W.TESTTYPE = '999999';
TESTTYPE A B
-------- ---------- ----------
10 1 2
10 1 3
10 1 4
问题是:我使用条件 AND W.TESTTYPE = '999999'
进行过滤,我期望的结果集应该是空的,但似乎该条件不起作用,秘密可能来自OR
,但为什么它不起作用?
It's a problem I encountered in the work and I simplify it as follows:
First, is the testcase
create table A_TESTB
(
A VARCHAR2(10),
B VARCHAR2(10)
);
insert into A_TESTB (A, B)
values ('1', '2');
insert into A_TESTB (A, B)
values ('1', '3');
insert into A_TESTB (A, B)
values ('1', '4');
commit;
SQL> select * from a_testb;
A B
---------- ----------
1 2
1 3
1 4
then,I use sql like below
SQL> SELECT *
2 FROM (SELECT '10' TESTTYPE, T.* FROM A_TESTB T) W
3 WHERE (W.A = '1' OR 1 = 2)
4 AND W.TESTTYPE = '999999';
TESTTYPE A B
-------- ---------- ----------
10 1 2
10 1 3
10 1 4
The question is : I have used the condition AND W.TESTTYPE = '999999'
to filter, and my expecting resultset should be empty,but it seems that the condition doesn't work ,the secret maybe from OR
, but why doesn't it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的结果集是空的!
我在
使用 TOAD 版本 10.5.0.41 的查询中使用 NO ROWS RETURNED:
我也在 SQL*Plus 中运行它,只是为了 100% 确定:
My result set is empty!
I am using
NO ROWS RETURNED for your query using TOAD release 10.5.0.41:
I run it also in SQL*Plus, just to be 100% sure: