How to treat MAX() of an empty table as 0 instead of NULL

前端 未结 3 1222
情书的邮戳
情书的邮戳 2020-12-29 23:15

I try to select max value from table

SELECT MAX(cid) FROM itemconfiguration;

However when table itemconfiguration is empty th

相关标签:
3条回答
  • 2020-12-30 00:05

    Just use Coalesce or NVL to handle NULLs.

    The following code will return 0 if MAX(cid) is NULL

    SELECT COALESCE(MAX(cid), 0)
    FROM   itemconfiguration
    
    0 讨论(0)
  • 2020-12-30 00:07

    SELECT NVL(MAX(cid), 0) FROM itemconfiguration;

    0 讨论(0)
  • 2020-12-30 00:12

    Can replace a number when max return null using ISNULL ,

    ISNULL(MAX(cid),0) FROM itemconfiguration;
    
    0 讨论(0)
提交回复
热议问题