A,B都不填就是select * from table?select * from table where null('XXX',a) = a and null('XXX',b) = b
sasacat 你那样不行,如果用户不给A赋值的话,则查询 select * from table where a is null and b='XXX' 这样一条记录也查不到,因为不存在A IS NULL的记录
不好意思,上面写错了 select * from table where nvl('XXX',a) = a and nvl('XXX',b) = b
select * from TABLE where ((a='XXX' )or (B is null)) and ((b='XXX')or(A is null))
((a='XXX' )or (a is null)) and ((b='XXX')or(b is null))----------------- 假如表中a不存在null的值,则a is null肯定为false,然后用户又没输入A,则a='XXX'也为false,所以((a='XXX' )or (a is null)) 即 (false or false) 结果为false,最后((a='XXX' )or (a is null)) and ((b='XXX')or(b is null))即 false and ((b='XXX')or(b is null))肯定也是fasle,不知道楼主是不是这个意思呢
to duanzilin(寻) 我的意思是a='XXX'是指从输入来的内容,如果用户没有输入,则a='无输入'
select * from table where a is null and b='XXX'
这样一条记录也查不到,因为不存在A IS NULL的记录
select * from table where nvl('XXX',a) = a and nvl('XXX',b) = b
where ((a='XXX' )or (B is null))
and ((b='XXX')or(A is null))
假如表中a不存在null的值,则a is null肯定为false,然后用户又没输入A,则a='XXX'也为false,所以((a='XXX' )or (a is null)) 即 (false or false) 结果为false,最后((a='XXX' )or (a is null)) and ((b='XXX')or(b is null))即 false and ((b='XXX')or(b is null))肯定也是fasle,不知道楼主是不是这个意思呢
我的意思是a='XXX'是指从输入来的内容,如果用户没有输入,则a='无输入'
可以加上1=1这样的条件,然后判断a,b又没有输入,有的话,就加上条件。要么就用duanzilin(寻) ( ) 的做法。