How Oracle 10g evaluates NULL in boolean expressions

你。 提交于 2019-12-12 09:48:20

问题


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 = null and the value of the dt_enddate is 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.

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

But it is not happening

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


回答1:


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

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

In this case, IF will treat UNKNOWN as false.

If i_relaunch can 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.

See these article for more information:

  • Nulls: Nothing to Worry About
  • Fundamentals of PL/SQL. Scroll down to - Handling Null Values in Comparisons and Conditional Statements


来源:https://stackoverflow.com/questions/2692046/how-oracle-10g-evaluates-null-in-boolean-expressions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!