クエリから行が返されない場合はnone, none, 0
の行を返すことができます。 james
とsmith
のエントリが存在しますが、エントリがhankers
のために存在しない、DBから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'));
:私はこのSQLを持っています。
ただし、このクエリはエントリが存在する場合にのみ返されます。 none, none, 0
を返しません。
私はここで間違っていますか?
EDIT:3つのハードコーディングされた値をlast
として渡していますが、(:last)
からgetJdbcTemplateまでの値をリストパラメータとして渡している場合は回避策を知りたいと思います。
あなたは、行数を使用することができ、ここのように:http://stackoverflow.com/questions/2884996/simple-check-for-select-query-empty-result – aguetat
どのデータベースを使用しましたか? – vipin
@vipin Oracle db – qollers