简体   繁体   中英

IIF statement in oracle sql developer

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

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';

Try decode function

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

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

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:

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM