大家好, 我最近有一个问题,请各位解答一个, 谢谢!
 A,select * from ab01 t where t.aab001 like '11%' or t.aab001 like 'b11%'
B,select * from ab01 t where t.aab001 like  表达式如何写我要达到的结果是, B语句要只用一个like,用表达式达到A要查到的结果.                          

解决方案 »

  1.   

    select * from ab01 where regexp_like(a,'[b]?11')
      

  2.   


    只能用正则,不能用like,3楼正解
      

  3.   


    您好,我现在是多查了一些数据.我要的表达式是:可能b存在,可能b不存在, 但一定要找到以11开头或b11开头的数据  
      

  4.   


    select * from ab01 where regexp_like(a,'^[b]?11')
      

  5.   

    select *
      from ab01 t
     where 'b' || replace(substr(aab001, 1, 3), 'b') like 'b11%'你看下这样行么,数据多可能会有性能问题
      

  6.   

    t.aab001 like '11%' or t.aab001 like 'b11%' 
    t.aab001 like 'b11%' 是 t.aab001 like '11%'的子集,两者或起来就是取最大集,等价于t.aab001 like '11%'。所以B:select * from ab01 t where t.aab001 like '11%'
    OVER!!!
      

  7.   

    不是10G 就不能用正则了,看看这个行不?笨了点,但能达到你的效果。SELECT *
      FROM AB01 T
     WHERE SUBSTR(T.AAB001, 1, 3) LIKE '%11%'
       AND SUBSTR(T.AAB001, 1, 1) IN ('b', '1')
      

  8.   


    我就郁闷了这样不能达到效果?with ab01 as (select 'b1111a' aab001 from dual
                   union 
                   select '111a' from dual
                   union
                   select '1a1b' from dual)
    select * 
      from ab01 t 
    where 'b' || replace(substr(aab001, 1, 3), 'b') like 'b11%' 
      

  9.   

    想了想,前面提到的两个不对,现在试下。有待学习提高阿with ab01 as (select 'b111a' aab001 from dual
                   union 
                   select '1b1' from dual
                   union
                   select '11aa' from dual
                   union 
                   select '11b' from dual)
    select * 
      from ab01 t 
    where replace(substr(aab001, 1, 1), 'b')||substr(aab001,2,2) like '11%' 
      

  10.   

    首选还是正则表达式,其他人的很多提议都可以实现,下面是我的提供的另一个选择:
    select * from ab01 t where decode(substr(t.aab001, 1, 3), 'b11', '11', substr(t.aab001, 1, 2)) = '11';