SQL Oracle 空条件检查“ ”条件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7215202/
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
Oracle empty conditions to check the ' ' condition
提问by reg10
How do I compare a VARCHAR2
variable, which is an empty value?
如何比较一个VARCHAR2
变量,它是一个空值?
回答by Karel Petranek
Oracle doesn't differentiate between empty strings and NULL. To check if a variable is an empty string, use the IS NULL
syntax.
Oracle 不区分空字符串和 NULL。要检查变量是否为空字符串,请使用IS NULL
语法。
回答by Ollie
You could use either of these:
您可以使用以下任一方法:
IF v_test IS NULL
THEN
-- Business Logic
or
或者
IF NVL(v_test, 'NULL') = 'NULL'
THEN
-- Business Logic
Your question does say "compare" a VARCHAR variable which is null so if you are comparing it to another variable then:
您的问题确实说“比较”一个为空的 VARCHAR 变量,因此如果您将它与另一个变量进行比较,则:
IF (v_test1 IS NULL and v_test2 IS NULL)
THEN
-- Business Logic
That would check if they are both null.
那将检查它们是否都为空。
Hope it helps...
希望能帮助到你...