表(NN_TEST)中某个字段(NN_VALUE)的值:
1,22,3,4,5我想判指定的数字是否在这个字段中,
比如我想判断 2  不是 22 select * from NN_TEST t
WHERE instr(NN_VALUE, '2')>0 
这个查询语句是有结果的, 
应该没有查询结果的,因为2不存在。请教大侠们,指点一下。

解决方案 »

  1.   

    regexp_instr参考这个http://blog.sina.com.cn/s/blog_6288f1400100lv79.html
      

  2.   


    select * from NN_TEST t
    where instr(','||NN_VALUE||',',',2,')>0;
      

  3.   

    逗号分割的。
    那么可以
    select * from NN_TEST t
    WHERE instr(NN_VALUE, '2,')>0
      

  4.   

    很妙啊。with t(str) as (
    select '33,22,2' from dual 
    union
    select '2,32,42' from dual 
    union 
    select '222,2222,22' from dual 
    )
    select str,regexp_instr(str,'^[2],|,[2]$') from t order by str ;STR         REGEXP_INSTR(STR,'^[2],|,[2]$')
    ----------- -------------------------------
    2,32,42                                   1
    222,2222,22                               0
    33,22,2                                   6