Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在运行一个查询来检索一个整数,但想要检查空值。如果为 null,我希望查询返回 0。我该怎么做?我在下面尝试了这个,但它不起作用
select NVL(A_COUNT, 0) from MYTABLE where VEH_YEAR = '2003';
如果 A_COUNT 为空,我希望查询返回 0。在上述情况下,我在 VEH_YEAR 列中没有值 2003。如果我在 VEH_YEAR 列中有值 2003 但 A_COUNT 为空,则查询有效。
更好的版本是,使用之前使用的Aggregate函数。MAXNVL
Aggregate
MAX
NVL
select NVL(MAX(A_COUNT),0) from MYTABLE where VEH_YEAR = '2003';
SELECT NVL((select A_COUNT from MYTABLE where VEH_YEAR = '2003'), 0) A_COUNT from dual;
这行得通。