存储过程中
传递N个值有些值为null我需要些SQL insert into tab select a,b,c,b from tab where x=1 and b= 2 and c=3;
现在是如果b的值2 传递过来的是NULL 那么我这条SQL 的判断 b 就不能=null 应该是SQL insert into tab select a,b,c,b from tab where x=1 and 1=1 and c=3;我想写成
SQL insert into tab select a,b,c,b from tab where (x=1 or 1=1)
and (b= 2 or 1=1)
and (c=3 or 1=1);但是没有判断null
请我 如果我传递过来的值为null 我对应的判断 就会是1=1 就不对该字段进行判断。谢谢。and (a!=null or a=1 or 1=1 )
不知道能不能行。。求答案ps: 我不想 EXECUTE IMMEDIATE SQL;
传递N个值有些值为null我需要些SQL insert into tab select a,b,c,b from tab where x=1 and b= 2 and c=3;
现在是如果b的值2 传递过来的是NULL 那么我这条SQL 的判断 b 就不能=null 应该是SQL insert into tab select a,b,c,b from tab where x=1 and 1=1 and c=3;我想写成
SQL insert into tab select a,b,c,b from tab where (x=1 or 1=1)
and (b= 2 or 1=1)
and (c=3 or 1=1);但是没有判断null
请我 如果我传递过来的值为null 我对应的判断 就会是1=1 就不对该字段进行判断。谢谢。and (a!=null or a=1 or 1=1 )
不知道能不能行。。求答案ps: 我不想 EXECUTE IMMEDIATE SQL;
解决方案 »
- 求教一个 SQL 的问题,十分感谢!
- VC+OO4O连接Oracle 10g数据库,如何打包才能在不装oracle 客户端的客户机上连接成功
- 我有一个大的回滚段,如何在我IMP 大量数据时指定使用这个大回滚段?
- Oracle递归查询!
- 怎么把表的第i行和第i+1行连接?
- 求PL/SQL帮助,最好是中文版,能检索的那种,谢谢!
- 请问怎样add一个子分区
- DBA STUDIO 中在 文件菜单中点击 从数据库添加到树中选项 无反映,问题会出在哪里?
- Oracle8.1.1.7作业运行失败~
- 如何获得trigger的脚本?如何获得表的脚本,如何获得包的脚本?
- 关于空格和数字拼串后空格丢失的问题,请高手释疑。
- 请教union结果多出n条记录的问题
在PL/SQL程序中先判断参数为NULL和不为NULL的情况。
然后再进一步做处理罢。
这里的1 2 3 应该是参数是吧
你这样还不是拼装SQL啊if x is not null then
sql := sql||' and 1=1';
end if;这样吧我说了我不想这样。能否直接在SQL的where 或者and 条件中判断掉
where case when t.a is null then 1 end =1
你确定 case when 能在where 后面使用?
insert into tab select a,b,c,b
from tab
where (x=1 or x is null) and (b= 2 or b is null) and (c=3 or c is null)