I try to select max value from table
我尝试从表中选择最大值
SELECT MAX(cid) FROM itemconfiguration;
However when table itemconfiguration
is empty the MAX(cid)
statements is evaluated to NULL
while i need a number. How to handle this and treat NULL
as 0 ?
然而,当表项配置为空时,MAX(cid)语句被计算为NULL,而我需要一个数字。如何处理这个并将NULL当作0 ?
2 个解决方案
#1
#2
4
SELECT NVL(MAX(cid), 0) FROM itemconfiguration;
从itemconfiguration中选择NVL(MAX(cid), 0);
#1
37
Just use Coalesce or NVL to handle NULLs.
只需使用Coalesce或NVL来处理NULLs。
The following code will return 0 if MAX(cid)
is NULL
如果MAX(cid)为NULL,下面的代码将返回0
SELECT COALESCE(MAX(cid), 0)
FROM itemconfiguration
#2
4
SELECT NVL(MAX(cid), 0) FROM itemconfiguration;
从itemconfiguration中选择NVL(MAX(cid), 0);