我查询一个数据表,想将某列既不是null也不是空格的行查出来。可是不行:
例如:select old_dept,re,dept_code,dept_name from cst_dept_syn where 1=1 and dept_name is not null and dept_name!=''
就啥也查不出来了。
如果我这样就能查出来, select old_dept,re,dept_code,dept_name from cst_dept_syn where 1=1 and dept_name is not null and dept_name || ' '!=' '真的不知道oracle是如何看待空字符串的。大家帮忙分析一下。

解决方案 »

  1.   

    oracle中''就是null
    查询的时候就是is null和is not null
      

  2.   

    把and dept_name!=''去掉就行了
      

  3.   

    空格是' '而不是''select old_dept,re,dept_code,dept_name from cst_dept_syn 
        where 1=1 and dept_name is not null and dept_name != ' '
    这样难道会查不出?
      

  4.   

    明白了。oracle的确把0长度字符串和null等同处理。如果一个列有0长度字符串或者null,我们要过滤掉好像 is not null 时 自动将null 和 0长度字符串过滤掉。
    而!=' ' 时  自动将null 和 0长度字符串和1长度字符串过滤掉。而 如果用 ='' 或者 !=''那么什么都查不出来。
      

  5.   

    但是如果用 is null 就将所有 null的查出来  而  =' '则只能将 值为 ' '的查出来。
    而如果随便一个 !='liu'什么的  null的也被忽略掉。如果想把所有 不等于 'liu' 的全查出来包括 null的,就需要:
    a!='liu' or a is null