【问题标题】:IIF statement in oracle sql developeroracle sql developer中的IIF语句
【发布时间】:2013-07-26 17:52:51
【问题描述】:

有一个我正在尝试转换为 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';

【问题讨论】:

  • IIF 是访问特定的。您需要将语法转换为目标数据库支持的内容。解码、大小写是执行此操作的两个主要示例。
  • 不仅访问而且 Transact SQL 具有内置函数 IIF。该问题与“通用” sql 区域有关。

标签: sql oracle ms-access-2007 oracle-sqldeveloper


【解决方案1】:

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

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

更多信息

【讨论】:

    【解决方案2】:

    可以使用NULLIFNVL2 的组合。

    如果vw_gdp_currentqry.LOCNOT 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';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多