【发布时间】:2016-11-12 08:03:40
【问题描述】:
如果查询没有返回行,我希望能够返回一行none, none, 0。我有这个 SQL:
select first, last, count(address)
from employee
where last in ('james', 'smith', 'hankers')
group by first, last
union all
select 'none', 'none', 0
from dual
where not exists (select * from employee where last in ('james', 'smith', 'hankers'));
从 DB 中,james 和 smith 的条目存在,但 hankers 不存在条目。
但此查询仅在条目存在时返回。不返回none, none, 0。
我在这里做错了什么?
编辑:在此示例中,我将 3 个硬编码值作为last 传递,但我想知道一个解决方法,如果我们通过 getJdbcTemplate 将值作为(:last) 这样的列表参数传递。
【问题讨论】:
-
你可以使用rowcount,像这里:stackoverflow.com/questions/2884996/…
-
你用的是哪个数据库?
-
好吧,我支持aguetat,但是他的例子在msSql中,但是在oracle中,可以选择count进行检查。
标签: sql jdbctemplate named-parameters