Oracle 错误:ORA-00905:缺少关键字
Posted
技术标签:
【中文标题】Oracle 错误:ORA-00905:缺少关键字【英文标题】:Oracle error : ORA- 00905 : Missing keyword 【发布时间】:2021-12-03 05:25:33 【问题描述】:我正在执行这条 SQL 语句:
MERGE INTO INTERVIEW OLD_R
USING NEW_INTERVIEW NEW_R
ON (NEW_R.REG_NO = OLD_R.REG_NO)
WHEN MATCHED
AND (NEW_R.NAME <> OLD_R.NAME OR NEW_R.MOB_NO <> OLD_R.MOB_NO)
THEN UPDATE SET
OLD_R.NAME = NEW_R.NAME,
OLD_R.MOB_NO = NEW_R.MOB_NO
WHEN NOT MATCHED BY OLD_R
THEN
INSERT(OLD_R.NAME, OLD_R.REG_NO, OLD_R.MOB_NO)
VALUES(NEW_R.NAME, NEW_R.REG_NO, NEW_R.MOB_NO)
WHEN NOT MATCHED BY NEW_R
THEN DELETE;
针对 Oracle 数据库备份名为 assignment
的表,但出现此错误:
ORA-00905:缺少关键字
【问题讨论】:
【参考方案1】:语法错误。应该是
MERGE INTO INTERVIEW OLD_R
USING NEW_INTERVIEW NEW_R
ON (NEW_R.REG_NO = OLD_R.REG_NO)
WHEN MATCHED
THEN
UPDATE SET OLD_R.NAME = NEW_R.NAME, OLD_R.MOB_NO = NEW_R.MOB_NO
WHERE NEW_R.NAME <> OLD_R.NAME
OR NEW_R.MOB_NO <> OLD_R.MOB_NO
WHEN NOT MATCHED
THEN
INSERT (OLD_R.NAME, OLD_R.REG_NO, OLD_R.MOB_NO)
VALUES (NEW_R.NAME, NEW_R.REG_NO, NEW_R.MOB_NO);
【讨论】:
【参考方案2】:WHEN MATCHED AND (NEW_R.NAME <> OLD_R.NAME OR NEW_R.MOB_NO <> OLD_R.MOB_NO) THEN UPDATE SET OLD_R.NAME = NEW_R.NAME, OLD_R.MOB_NO = NEW_R.MOB_NO
应该是
WHEN MATCHED THEN
UPDATE
SET OLD_R.NAME = NEW_R.NAME,
OLD_R.MOB_NO = NEW_R.MOB_NO
WHERE NEW_R.NAME <> OLD_R.NAME OR NEW_R.MOB_NO <> OLD_R.MOB_NO
然后
WHEN NOT MATCHED BY OLD_R
应该是:
WHEN NOT MATCHED
和:
WHEN NOT MATCHED BY NEW_R THEN DELETE;
不是 Oracle 支持的语法;您需要使用单独的 DELETE
语句删除这些行。
【讨论】:
以上是关于Oracle 错误:ORA-00905:缺少关键字的主要内容,如果未能解决你的问题,请参考以下文章
无法更正 Oracle 错误 ORA-00905 SQL 中缺少关键字