今天遇到个需求,要根据excel的一列中的数据去查询得出一列内容并补充到excel表中,刚开始我想的是,直接一条一条查询,union all一下就可以了,但是查出来后发现,少了几百条数据,后来一核对,发现当根据查询条件没有查出结果集时,将不会返回列,于是在bing一下,依然没有简单的解决方法,后来想出一种解决办法,可能效率不高,但至少简单明了的满足了需求,记录一下
select
case when
exists (select name from user where idcard='******')
then
(select name from user where idcard='******')
else
'无该用户'
end
from dual