提问人:ownmurad 提问时间:11/19/2020 最后编辑:marc_sownmurad 更新时间:11/19/2020 访问量:228
ORACLE SQL CASE 语句 - 出现错误
ORACLE SQL CASE statement - getting error
问:
SELECT
ZOC, UNIT,
CASE ZOC
WHEN ZOC = '51' THEN 'ZONE OPERATION KHULNA'
WHEN ZOC = '52' THEN 'ZONE OPERATION JESSORE'
WHEN XOC = '53' THEN 'ZONE OPERATION KUSHTIA'
END
FROM
GNGRB.BS_CLOSING
ORDER BY
ZOC;
我收到此错误:
ORA-00905:缺少关键字
00905。00000 - “缺少关键字”
*原因: *操作: 第 16 行出错 列:
10
答:
1赞
juergen d
11/19/2020
#1
SELECT ZOC, UNIT, CASE WHEN ZOC = '51' THEN 'ZONE OPERATION KHULNA'
WHEN ZOC = '52' THEN 'ZONE OPERATION JESSORE'
WHEN ZOC = '53' THEN 'ZONE OPERATION KUSHTIA'
END
FROM GNGRB.BS_CLOSING
ORDER BY ZOC;
0赞
Popeye
11/19/2020
#2
语句有两种写法。CASE..WHEN
CASE WHEN COLUMN_NAME = VALUE1 THEN ... WHEN COLUMN_NAME = VALUE2 THEN .. END
CASE COLUMN_NAME WHEN VALUE1 THEN ... WHEN VALUE2 THEN ... END
在你的情况下,你可以写成这样:
SELECT ZOC,
UNIT,
CASE
--ZOC -- just remove this
WHEN ZOC = '51' THEN
'ZONE OPERATION KHULNA'
WHEN ZOC = '52' THEN
'ZONE OPERATION JESSORE'
WHEN ZOC = '53' THEN
'ZONE OPERATION KUSHTIA'
END
FROM GNGRB.BS_CLOSING
ORDER BY ZOC;
--或
SELECT ZOC,
UNIT,
CASE ZOC
WHEN '51' THEN
'ZONE OPERATION KHULNA'
WHEN '52' THEN
'ZONE OPERATION JESSORE'
WHEN '53' THEN
'ZONE OPERATION KUSHTIA'
END
FROM GNGRB.BS_CLOSING
ORDER BY ZOC;
2赞
Thorsten Kettner
11/19/2020
#3
您正在混合两种语法。决定一个。
CASE zoc WHEN ...
SELECT
zoc, unit,
CASE zoc
WHEN 51 THEN 'ZONE OPERATION KHULNA'
WHEN 52 THEN 'ZONE OPERATION JESSORE'
WHEN 53 THEN 'ZONE OPERATION KUSHTIA'
END
FROM ...
CASE WHEN ...
SELECT
zoc, unit,
CASE
WHEN zoc = 51 THEN 'ZONE OPERATION KHULNA'
WHEN zoc = 52 THEN 'ZONE OPERATION JESSORE'
WHEN zoc = 53 THEN 'ZONE OPERATION KUSHTIA'
END
FROM ...
评论
zoc
'51'
WHEN ZOC = 51