日期:2014-05-17  浏览次数:21005 次

Oracle nvl函数问题
String queryString = " from TProject where nvl(submit,'no') = 'no' ";

nvl(submit,'no')的意思是 假如submit字段值为空 那么submit=no  

那么nvl(submit,'no')='no'的意思是什么了 这个字段里只有yes 空 和 no三个值可选 用这句语句查询出的结果的submit的值都是空值或者no ,sumbit值为yes 的记录显示不出来 ,这不是我的疑问 这是我说明这语句的查询出来的结果 我的疑问是


nvl(submit,'no')='no'的意思是什么了

------解决方案--------------------
其实就相当于:
SQL code

String queryString = " from TProject where nvl(submit,'no') <> 'yes'

------解决方案--------------------
SQL code

String queryString = " from TProject where nvl(submit,'no') = 'no' ";

------解决方案--------------------
from TProject where nvl(submit,'no') = 'no' 

就是
select * from TProject where submit is null;
------解决方案--------------------
探讨

from TProject where nvl(submit,'no') = 'no'

就是
select * from TProject where submit is null;

------解决方案--------------------
测试数据:
SQL code

CREATE TABLE TProject
(
    ID NUMBER(4),
    sub VARCHAR2(20)    
);
INSERT INTO TProject VALUES(1, 'yes');
INSERT INTO TProject VALUES(2, 'no');
INSERT INTO TProject VALUES(3, NULL);