Why does NVL always evaluate 2nd parameter

后端 未结 4 788
清酒与你
清酒与你 2020-12-11 16:53

Does anyone know, why Oracle\'s NVL (and NVL2) function always evaluate the second parameter, even if the first parameter is not NULL?

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 17:42

    Here is a post where Tom Kyte confirms that decode and case short circuit but not nvl but he doesn't give justification or documentation for why. Just states it to be:

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:926029357278#14932880517348

    So in your case you should use decode or case instead of nvl if an expensive function will be called in your query.

提交回复
热议问题