ITPub博客

首页 > 数据库 > Oracle > and or运算优先级的问题

and or运算优先级的问题

原创 Oracle 作者:bestpaydata 时间:2016-04-28 09:46:20 0 删除 编辑

xulijia

and优先级比较高 or优先级低


select * from test where condition1 or condition2 and condition3;
其执行效果与下面的sql等价
select * from test where condition1 or (condition2 and condition3);

和这个的意思不一样哦
select * from test where (condition1 or condition2) and condition3;


create table test (col1 number,col2 number,col3 number);
insert into test values (1,2,3);
insert into test values (1,2,4);
insert into test values (1,3,5);
insert into test values (2,3,5);
insert into test values (7,3,5);

      COL1       COL2       COL3
---------- ---------- ----------
         1          2          4
         1          3          5
         2          3          5
         7          3          5
         2          2          3

select * from test where col1=2 or col2=3 and col3=5;
      COL1       COL2       COL3
---------- ---------- ----------
         1          3          5
         2          3          5
         7          3          5
         2          2          3

select * from test where col1=2 or (col2=3 and col3=5);
      COL1       COL2       COL3
---------- ---------- ----------
         1          3          5
         2          3          5
         7          3          5
         2          2          3

select * from test where (col1=2 or col2=3) and col3=5;
      COL1       COL2       COL3
---------- ---------- ----------
         1          3          5
         2          3          5
         7          3          5


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30109892/viewspace-2089849/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-01-19

  • 博文量
    126
  • 访问量
    1054935