oracle sql developer中的IIF语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17887867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IIF statement in oracle sql developer
提问by user2623359
Have an access query that i'm trying to convert to oracle sql dev. and seems that i have my error at IIf(vw_gdp_currentqry.LOC='0300','F','P') AS SRCE,can someone help please
有一个我正在尝试转换为 oracle sql dev 的访问查询。似乎我在 IIf(vw_gdp_currentqry.LOC='0300','F','P') AS SRCE 有错误,有人可以帮忙吗
SELECT
vw_gdp_currentqry.YEAR,
vw_gdp_currentqry.LOC,
**IIf(vw_gdp_currentqry.LOC='0300','F','P') AS SRCE,**
vw_gdp_currentqry.METHOD,
vw_gdp_currentqry.current_value
FROM vw_gdp_currentqry
WHERE vw_gdp_currentqry.IND)='TOT';
回答by Robert
Try decode
function
试用decode
功能
SELECT
vw_gdp_currentqry.YEAR,
vw_gdp_currentqry.LOC,
decode (vw_gdp_currentqry.LOC,'0300', 'F', 'P' ) AS SRCE,
vw_gdp_currentqry.METHOD,
vw_gdp_currentqry.current_value
FROM vw_gdp_currentqry
WHERE vw_gdp_currentqry.IND='TOT';
or with case
syntax
或使用case
语法
SELECT
vw_gdp_currentqry.YEAR,
vw_gdp_currentqry.LOC,
case vw_gdp_currentqry.LOC
when '0300' then 'F'
else 'P'
end AS SRCE,
vw_gdp_currentqry.METHOD,
vw_gdp_currentqry.current_value
FROM vw_gdp_currentqry
WHERE vw_gdp_currentqry.IND='TOT';
More information
更多信息
回答by Skorpion
a combination of NULLIF and NVL2. You can only use this if vw_gdp_currentqry.LOC is NOT NULL, which it is in your case:
NULLIF 和 NVL2 的组合。您只能在 vw_gdp_currentqry.LOC 不为 NULL 时使用它,这就是您的情况:
SELECT
vw_gdp_currentqry.YEAR,
vw_gdp_currentqry.LOC,
nvl2(nullif(vw_gdp_currentqry.LOC,'0300'),'P','F'),
vw_gdp_currentqry.METHOD,
vw_gdp_currentqry.current_value
FROM vw_gdp_currentqry
WHERE vw_gdp_currentqry.IND='TOT';