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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:49:15  来源:igfitidea点击:

IIF statement in oracle sql developer

sqloraclems-access-2007oracle-sqldeveloper

提问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 decodefunction

试用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 casesyntax

或使用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';