首页 > 数据库 > Oracle > and or运算优先级的问题
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/ ,如需转载,请注明出处,否则将追究法律责任。