Oracle 10g 如何在布尔表达式中评估 NULL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2692046/
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-18 20:28:15  来源:igfitidea点击:

How Oracle 10g evaluates NULL in boolean expressions

oraclenulloracle10gboolean

提问by Phani Kumar PV

if not (i_ReLaunch = 1 and (dt_enddate is not null))

How this epression will be evaluated in Oracle 10g when the input value of the i_ReLaunch = nulland the value of the dt_enddateis not null it is entering the loop. According to the rules in normal c# and all it should not enter the loop as it will be as follows with the values.

当 the 的输入值i_ReLaunch = null和 的值dt_enddate不为空时,如何在 Oracle 10g 中评估此 epression 将进入循环。根据普通c#中的规则,它不应该进入循环,因为它的值如下。

If( not(false and (true)) = if not( false) =if( true)which implies it should enters the loop

If( not(false and (true)) = if not( false) =if( true)这意味着它应该进入循环

But it is not happening

但它没有发生

Can someone let me know if i am wrong at any place

有人可以让我知道我是否在任何地方错了

采纳答案by zendar

Boolean operations with NULL value in Oracle return UNKNOWN- not true or false. So you have something like this:

Oracle 中具有 NULL 值的布尔运算返回UNKNOWN- 不是 true 或 false。所以你有这样的事情:

If( not(UNKNOWN and (true)) = if not( UNKNOWN) =if( UNKNOWN )

In this case, IFwill treat UNKNOWN as false.

在这种情况下,IF将 UNKNOWN 视为 false。

If i_relaunchcan be null, then you need to use some of NULL handling functions(NVL, NVL2, NULLIF, COALESCE, LNNVL) to be sure that you have correct result.

如果i_relaunch可以为空,那么您需要使用一些空处理函数( NVL, NVL2, NULLIF, COALESCE, LNNVL) 来确保您得到正确的结果。

See these article for more information:

有关更多信息,请参阅这些文章: