现在的位置: 首页 > 综合 > 正文

当查询没有数据返回时返回一行默认值sql

2018年02月07日 ⁄ 综合 ⁄ 共 174字 ⁄ 字号 评论关闭

select  id,name from test where id=1 group by id,name
union all
select 0 id,'0' name from dual where (select count(*) from test where id=1) =0

--当一个查询没有返回任何行,又想返回一行,而且返回值为0,可以用如上语句。

缺点:同一个语句执行了两次,耗费资源

抱歉!评论已关闭.