如题:select * 
from tab t 
where t.col1 like 
'%' || lower(replace(replace(replace(replace('<','<','<<'),'>','<>'), '%', '<%'), '_', '<_')) || '%'
escape '<';我输入:“<”、“<>”、“%”、“_”没错!
但是输入“>”后报:
ORA-01424:转义字符之后字符缺失或非法
要求输入的字符中含有“<”、“>”、“<>”、“%”、“_”也能查出来! 这样的sql怎样写? 大家帮帮忙!
  使用oracle中正则表达式也行!

解决方案 »

  1.   

    with tmp as
    (
    select 'abc<' c1 from dual
    union all
    select '>ed12' c1 from dual
    union all
    select '33<>12' c1 from dual
    union all
    select 'dd%aa' c1 from dual
    union all
    select '_333' c1 from dual
    union all
    select 'abc333' c1 from dual
    )
    select * from tmp
    where regexp_like (c1, '[<>%_]');
      

  2.   

    还有oracle中正则表达式的例子吗?
      有具体的测试案例最好!
      

  3.   

    SELECT
      REGEXP_REPLACE(phone_number,
                     '([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})',
                     '(\1) \2-\3') "REGEXP_REPLACE"
      FROM employees;REGEXP_REPLACE
    --------------------------------------------------------------------------------
    (515) 123-4567
    (515) 123-4568
    (515) 123-4569
    (590) 423-4567
    . . .
      

  4.   

    除去多餘的空格SELECT
      REGEXP_REPLACE('500   Oracle     Parkway,    Redwood  Shores, CA',
                     '( ){2,}', ' ') "REGEXP_REPLACE"
      FROM DUAL;REGEXP_REPLACE
    --------------------------------------
    500 Oracle Parkway, Redwood Shores, CA