sqlnvl

NVL Function in SQL


what excatly 1 - NVL(up, 0) down this statement mean , is it giving me the contradiction of up ?


Solution

  • Presumably, up is a value that can take up to three values: 0, 1, and NULL.

    The NVL() function is a database-specific function for COALESCE(). They do the same thing.

    So, simply look at what the results are:

     up     1 - coalesce(up, 0)
      1               0
      0               1
    NULL              1
    

    So, it is "flipping the switch". That is, when "up" is "true", then it switches it to "false". It treats 0 as "false" for this purpose.