具体是这样的:
    我查询的一个字段需要用到模糊匹配,这个字段存在空值。当你要匹配时直接输入字符串匹配就可以了。但有时输入匹配字符串为空时如何将所有记录包括空值都匹配出来。SQL

解决方案 »

  1.   

    select * from emp where comm like '%0%' or nvl2('a',0,1)=1;
    select * from emp where comm like '%%' or nvl2(null,0,1)=1;
      

  2.   

    where 字段 like '模糊匹配' or 字段is null;
      

  3.   

    参数为NULL和不为NULL的情况,写到程序中,参数化就OK了
    select * from emp where comm like '%0%' or nvl2('0',0,1)=1;
    select * from emp where comm like '%%' or nvl2(null,0,1)=1;
      

  4.   

    where 字段 like '%字符串%' or 字段is null;
      

  5.   

    where 字段 like '模糊匹配' or 匹配 is null;
      

  6.   

    判断一下有没有输入不就可以了,类似这样(输入 is not null and 字段 like 输入||'%') or (输入 is null and 字段 is null)
      

  7.   

    where nvl(字段,' ') like '%模糊内容%'