我查询一个数据表,想将某列既不是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是如何看待空字符串的。大家帮忙分析一下。
例如: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是如何看待空字符串的。大家帮忙分析一下。
查询的时候就是is null和is not null
where 1=1 and dept_name is not null and dept_name != ' '
这样难道会查不出?
而!=' ' 时 自动将null 和 0长度字符串和1长度字符串过滤掉。而 如果用 ='' 或者 !=''那么什么都查不出来。
而如果随便一个 !='liu'什么的 null的也被忽略掉。如果想把所有 不等于 'liu' 的全查出来包括 null的,就需要:
a!='liu' or a is null