问题是这样的
     存储过程中有一段sql语句类似这个, 
     select * from table_1 where c_1=‘Y’ and c_2 like 参数
 现在这个like条件在某种情况下有,在其他情况下没有.这个参数应该怎么写。 我是这样想的, like '%'||参数||'%',但是不行。纠结啊 。
求大神帮助。
先谢谢了

解决方案 »

  1.   


      create or replace procedure P1 (c1 in number, c2 in varchar2 default 'N')
      is
      begin
        if 'N' = c2 then
            select * from table_1 where c_1=‘Y’ and c_2 like 参数;
        elsif
            select * from table_1 where c_1=‘Y’;
        end;
      end;
      

  2.   

    sorry    'N' <> c2
      

  3.   


    select * from table_1 
    where c_1=‘Y’ and 
          nvl(c_2,参数) like ‘%'||参数||'%';
      

  4.   

    没有直接解决的么 ?我的这个sql语句特别长 要这样写的话 就更长了  而且 像这个的参数 不只一个 至少两个,怎么办啊?
      

  5.   

    可以参考3楼 但性能不保证。可以用动态sql吗?
      

  6.   

    做oracle 的instr函数就可以了,性能比like强很多