Handling Null in Greatest function in Oracle

后端 未结 9 1387
轮回少年
轮回少年 2021-02-14 05:36

I want to compare two dates from two columns and get the greatest and then compare against a date value.The two column can hold NULL values too.For example I want the below OUTP

9条回答
  •  天涯浪人
    2021-02-14 06:23

    You might try the following:

    SELECT cola, colb, COALESCE( GREATEST( cola, colb ), cola, colb ) AS output
      FROM yourtable;
    

    The reason for COALESCE() is that GREATEST() returns NULL if either of the parameters is NULL.

提交回复
热议问题