我有以下SQL
Select *
from PS_VENDOR
WHERE VENDOR IN ('111','222','333','444')
其中444 VENDOR不存在。但是当我运行SQL时,我应该从IN CLAUSE获取所有4行,并且444只填充BLANK或'X'
我尝试了以下操作并且无法正常工作
Select *
from PS_VENDOR
WHERE NVL(VENDOR IN ('111','222','333','444'), 'X');
答案 0 :(得分:6)
使用CTE保存您的值,左连接
with V1 as
(
select '111' as VV from dual
union all
select '222' as VV from dual
union all
select '333' as VV from dual
union all
select '444' as VV from dual
)
select VV, PS_VENDOR.*
from V1
left join PS_VENDOR
on VENDOR = VV