一个sql语句   字段nbr     nbr以8831开头  ,后4位不包括4或者7,sql怎样写?求解......

解决方案 »

  1.   

    nbr like '8831%' and substr(nbr,-4) not like '%4%' and substr(nbr,-4) not like '%7%' 
      

  2.   

    nbr like '8831%' and substr(nbr,4,4) not like '%4%' and substr(nbr,4,4) not like '%7%'
      

  3.   


    nbr like '8831%' and (instr(substr(nbr,-4),'4')<0 or instr(substr(nbr,-4),'7')<0)
      

  4.   


    with temp as (
         select '8831432568987' id from dual
         union all 
         select '88313256898' id from dual
    )
    select id from temp t 
    where length(replace(t.id,'4','')) = length(t.id)
    and length(replace(t.id,'7','')) = length(t.id)
    and substr(t.id,0,4) = '8831';
      

  5.   

    改下select id from temp t 
    where length(REGEXP_REPLACE(t.id,'4|7','')) = length(t.id)
    and substr(t.id,0,4) = '8831';
      

  6.   

    倒,测试没
    SQL> select * from t_like;
     
             ID NAME
    ----------- --------------------------------------------------------------------------------
              1 88311234
              2 88311235
              2 88211236
     
    SQL> select * from t_like t where t.name like '8831%' and substr(name,-4) not like '%7%' and substr(name,-4) not like '%4%';
     
             ID NAME
    ----------- --------------------------------------------------------------------------------
              2 88311235
     
    SQL> 
      

  7.   

    是不是你的字段最后有空字符,trim下.
      

  8.   

    段nbr nbr以8831开头 ,后4位不包括4或者7,sql怎样写?求解......
    select * from 表 where nbr like '8831%' and 
    substr(nbr,length(nbr)-4)  not like '%4%' and
    substr(nbr,len(nbr)-4) not like '%7%'  
      

  9.   


    select * from 表 where nbr like '8831%' and  
    substr(nbr,length(nbr)-4) not like '%4%' and
    substr(nbr,len(nbr)-4) not like '%7%'