SQL - 语法中缺少关键字
SQL - missing keyword in case when syntax
我收到这条错误消息
missing keyword
有什么建议吗?谢谢
CASE WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=0
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 4000
then 'ASSET'
ELSE CASE WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=4000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 8000
then 'LIABILITY'
ELSE CASE WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=8000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 9000
then 'OFF BALANCE SHEET ASSET'
ELSE CASE WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=9000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 10000
then 'OFF BALANCE SHEET LIABILITY' end as ASSET_TYPE,
解决方案是:
case when substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=0 and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 4000 then 'ASSET'
when substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=4000 and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 8000 then 'LIABILITY'
when substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=8000 and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 9000 then 'OFF BALANCE SHEET ASSET'
when substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=9000 and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 10000 then 'OFF BALANCE SHEET LIABILITY'
else '' end as ASSET_TYPE,
谢谢
我认为您在案例陈述中使用了更多 "CASE" 个词。在每个 "Then" 之后删除 "ELSE CASE"。 Refer this Oracle Documentation
CASE WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=0
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 4000
then 'ASSET'
WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=4000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 8000
then 'LIABILITY'
WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=8000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 9000
then 'OFF BALANCE SHEET ASSET'
WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=9000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 10000
then 'OFF BALANCE SHEET LIABILITY'
END as ASSET_TYPE,
一般语法为
CASE
WHEN col = 1 THEN 'Active'
WHEN col = 2 THEN 'Inactive'
WHEN col = 3 THEN 'Terminated'
END AS StatusText
我收到这条错误消息
missing keyword
有什么建议吗?谢谢
CASE WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=0
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 4000
then 'ASSET'
ELSE CASE WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=4000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 8000
then 'LIABILITY'
ELSE CASE WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=8000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 9000
then 'OFF BALANCE SHEET ASSET'
ELSE CASE WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=9000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 10000
then 'OFF BALANCE SHEET LIABILITY' end as ASSET_TYPE,
解决方案是:
case when substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=0 and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 4000 then 'ASSET'
when substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=4000 and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 8000 then 'LIABILITY'
when substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=8000 and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 9000 then 'OFF BALANCE SHEET ASSET'
when substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=9000 and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 10000 then 'OFF BALANCE SHEET LIABILITY'
else '' end as ASSET_TYPE,
谢谢
我认为您在案例陈述中使用了更多 "CASE" 个词。在每个 "Then" 之后删除 "ELSE CASE"。 Refer this Oracle Documentation
CASE WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=0
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 4000
then 'ASSET'
WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=4000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 8000
then 'LIABILITY'
WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=8000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 9000
then 'OFF BALANCE SHEET ASSET'
WHEN
substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4)>=9000
and substr(M1.M_GL_LINE_NO,length(M1.M_GL_LINE_NO - 4),4) < 10000
then 'OFF BALANCE SHEET LIABILITY'
END as ASSET_TYPE,
一般语法为
CASE
WHEN col = 1 THEN 'Active'
WHEN col = 2 THEN 'Inactive'
WHEN col = 3 THEN 'Terminated'
END AS StatusText