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