项目中碰到一个查询到问题 使用到了SUM()函数
List<PutStorageDetail> initPutStorage = putStorageDetailDao.getInitPutStorageNoSku(stock);
这段代码中,由于查询使用到了SUM()函数,导致虽然没有任何记录,但是返回之后
initPutStorage 的size()为1 但是是null
导致后续代码报错
解决方法
SELECT
COALESCE(CAST(SUM(storage_count) AS DECIMAL(10, 2)), 0.00) AS storage_count
From
XXX
使用
COALESCE函数,该函数的作用是返回传入的参数中第一个非null的值