请教一个关于模糊查询来过滤数据的sql语句 需要对表A中的a字段来进行条件过滤,
原来的写法就是 not like '%x%',not like '%xx%',not like '%xxx%'这样,每次手工改程序,
觉得改程序麻烦,想建一个表保存过滤条件,用来进行模糊过滤,
达到类似not in (select *) 的目的,请高手指点。
------解决方案-------------------- with test as (
select 'x' as str from dual
union all
select 'xx' as str from dual
union all
select 'xxx' as str from dual
)
select * from test where regexp_like(str,'x+')
=========================
1 x
2 xx
3 xxx ------解决方案--------------------
declare
v_str_like varchar2(2000);
begin
for c in ( select 'x' as str from dual
union all
select 'xx' as str from dual
union all
select 'xxx' as str from dual)
loop
v_str_like:=v_str_like ------解决方案-------------------- 'not like ''%' ------解决方案-------------------- c.str ------解决方案-------------------- '%'',';
end loop;
dbms_output.put_line(RTrim(v_str_like, ','));
end;