如果模糊匹配的条件中含有“_”或者"%"这种通配符的字符,在oracle中如果不使用escape,是否能够通过like实现模糊匹配?例如:select * from tbl_1 where name like 'abc_%'
我这里想查询出以‘abc_’开头的name相应记录在sqlserver或者sybase中可以使用转换为select * from tbl_1 where name like 'abc[_]%'实现,oracle是否也有类似的方法? 多谢~

解决方案 »

  1.   

    --使用escape指定一个字符来转义,如指定\
    select * from tbl_1 where name like 'abc\_%' escape '\';
    --10g及以上可以使用正则表达式
    select * from tbl_1 where regexp_like (name,'abc_');
      

  2.   

    采用别的办法SQL> with tmp as
      2  (select 'abc_de' str from dual
      3  union all
      4  select 'qbabc_d' from dual)
      5  select * from tmp where instr(str,'abc_')=1;
     
    STR
    -------
    abc_de不过为了效率考虑可能要建立函数索引了
      

  3.   

    1.用以下看看你oracle的转义字符时什么
    SQL> SET ESCAPE ON
    SQL> SHOW ESCAPE
    escape "?" 2.select * from tbl_1 where name like 'abc?_%'
      

  4.   

    正则表达式也可以这样写:
    select * from a where regexp_like(col,'abc[_]');但是和sql是不一样的!
      

  5.   


    因为项目要支持sqlserver,sybase以及oracle三种数据库,所以使用了sourceProDB作适配,在sourceProDB中似乎不支持escape和regexp_like,是否还有其他方法呢?