将Access IIF转换为oracle

时间:2013-07-23 18:10:02

标签: sql oracle oracle-sqldeveloper iif

IIf(VW_GE_ALL_YEARQRY.DEP =“AG”,“AG”,“OT”)AS DEPT 转换为Oracle

时出现问题
Select
VW_GE_ALL_YEARQRY.year,
VW_GE_ALL_YEARQRY.LOC,
VW_GE_ALL_YEARQRY.CAT,
VW_GE_ALL_YEARQRY.TY,
(case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end) as DEPT,
VW_GE_ALL_YEARQRY.SRCE,
Sum(VW_GE_ALL_YEARQRY.EXPEND * 0.001) As EXP
From
VW_GE_ALL_YEARQRY
GROUP BY VW_GE_ALL_YEARQRY.year, VW_GE_ALL_YEARQRY.LOC, VW_GE_ALL_YEARQRY.CAT, VW_GE_ALL_YEARQRY.TY, (case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end) as DEPT, VW_GE_ALL_YEARQRY.SRCE
HAVING (((Sum(VW_GE_ALL_YEARQRY.EXPEND * 0.001)))<>0);

查询告诉我,我有一个错误,此时似乎微不足道

Error at Command Line:11 Column:169
Error report:
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:

3 个答案:

答案 0 :(得分:1)

如果唯一的问题是您的文字中的问题,那么很容易。使用case(ANSI标准):

(case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end) as DEPT

以下是您的查询的完整版本:

Select v.year, v.LOC, v.CAT, v.TY,
       (case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end) as DEPT
       v.SRCE,
       Sum(v.EXPEND * 0.001) As EXP
From VW_GE_ALL_YEARQRY v
GROUP BY v.year, v.LOC, v.CAT, v.TY,
         (case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end), v.SRCE
HAVING Sum(v.EXPEND * 0.001) <> 0;

我通过使用表别名简化了它。我从as DEPT子句中删除了group by。而且,我用单引号字符串替换了双引号字符串。

答案 1 :(得分:1)

你可以使用DECODE()或更好的CASE WHEN

答案 2 :(得分:0)

您可以替换

IIf(VW_GE_ALL_YEARQRY.DEP="AG","AG","OT")

CASE WHEN VW_GE_ALL_YEARQRY.DEP='AG' THEN 'AG' ELSE 'OT' END

分享并享受。