当前位置: 代码迷 >> Oracle开发 >> 请问一个有关字符串条件的有关问题
  详细解决方案

请问一个有关字符串条件的有关问题

热度:66   发布时间:2016-04-24 06:27:33.0
请教一个有关字符串条件的问题
本帖最后由 feng_zy 于 2015-05-07 15:52:10 编辑
select * from operator where ( pwd is null and ' ' =' '  or pwd='') and oper='9004'

select * from operator where ( pwd is null  or pwd='') and oper='9004'

请问这两条语句在oracle中为什么会得到不同的结果?
在sqlserver里是一样的

oracle中不允许''=''这种条件形式?因为我把它改成 '1'='1'就正常了

begin
    if('' <> '') then
        dbms_output.put_line('不等');
    else
        dbms_output.put_line('相等');
    end if;
end;
我用这个在oracle中执行又输出是相等的,请各位指点迷津...



------解决思路----------------------
‘’在oracle里面为null。null比较即不相等也不不相等。不能比较
------解决思路----------------------
在 select 语句中, '' 和 NULL ,视同一个东西,且只能使用 is null 这种形式来比较

比如,你有写了如下语句,也是查不出任何数据来的
select * from mytable where  ''= '' 
  相关解决方案