SQL Oracle 10g:列为空,但不为空或空字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4796356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 09:01:55  来源:igfitidea点击:

Oracle 10g: column is blank, but is not null or an empty string

sqloracle

提问by Josh

I have a column in a table that is blank. The weird thing is that it does not appear to be null or an empty string. So, if I do this:

我在一个空白的表格中有一个列。奇怪的是,它似乎不是 null 或空字符串。所以,如果我这样做:

SELECT * 
  FROM TABLE 
 WHERE column IS NULL

...or:

...或者:

SELECT * 
  FROM TABLE 
 WHERE column = ''

I get nothing. Thoughts?

我什么也得不到。想法?

回答by álvaro González

Issue this query:

发出此查询:

SELECT column, DUMP(column, 1016)
FROM table

It'll show the exact contents.

它将显示确切的内容。

Related: Oracle does not allow empty strings; they're silently converted to NULL.

相关:Oracle 不允许空字符串;他们默默地转换为NULL.

回答by a_horse_with_no_name

Maybe the column contains only spaces?

也许该列只包含空格?

Did you try

你试过了吗

select * 
from table 
where trim(column) is null

回答by Marc B

Oracle's got a basically permanent annoyance that empty strings are treated as null. However, are you sure that's an empty string? It could be an otherwise invisible character, such as a space or tab/linebreak/linefeed/etc... What does the string length show when you do select length(column) from table?

Oracle 有一个基本永久的烦恼,即空字符串被视为空字符串。但是,您确定这是一个空字符串吗?它可能是一个不可见的字符,例如空格或制表符/换行符/换行符/等......当你这样做时,字符串长度显示什么select length(column) from table

回答by Chandu

Try this:

尝试这个:

SELECT *    
  FROM TABLE   
 WHERE TRIM(column) IS NULL

回答by Benoit

If your column is not VARCHAR2but CHAR(N)then insertion of an empty string is padded. See what Tom Kyte tells about this

如果您的列不是VARCHAR2CHAR(N)则填充空字符串的插入。看看Tom Kyte 是怎么说的