日期:2014-05-17  浏览次数:20868 次

请教一个关于模糊查询来过滤数据的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
------解决方案--------------------
引用:
引用:把条件表循环 直接拼出后名的not like '%x%',not like '%xx%',not like '%xxx%'的字符串不就好了

正解,或者在程序里循环。一条SQL语句搞定,额也想知道,请高手指教!


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;