存储过程中 
传递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;

解决方案 »

  1.   

    可以考虑换个思路,
    在PL/SQL程序中先判断参数为NULL和不为NULL的情况。
    然后再进一步做处理罢。
      

  2.   

     insert into tab select a,b,c,b from tab where x=1 and b= 2 and c=3;
    这里的1 2 3 应该是参数是吧
      

  3.   

     
    你这样还不是拼装SQL啊if x is not null then 
    sql := sql||' and 1=1';
    end if;这样吧我说了我不想这样。能否直接在SQL的where 或者and 条件中判断掉
      

  4.   

    select * from tab t
    where case when t.a is null then 1 end =1
      

  5.   


    你确定 case when 能在where 后面使用?
      

  6.   

    试下这样可以不
    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)