Handling Null in Greatest function in Oracle

后端 未结 9 1385
轮回少年
轮回少年 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:18

    I tried this..found after googling

    WITH ABC AS ( SELECT NULL AS col1 , NULL AS col2 FROM dual UNION
     SELECT NULL , DATE'2013-08-12' FROM dual UNION
      SELECT  DATE'2013-08-12' , NULL FROM dual UNION
       SELECT  DATE'2013-08-12',  DATE'2013-09-12' FROM dual)
    
       SELECT col1, col2 , substr(greatest('x'||col1,'x'||col2),2)
          FROM ABC;
    

提交回复
热议问题