Oracle执行INSERT ALL批量插入报ORA-00928缺失SELECT关键字错误
问题现象
执行Oracle批量插入语句时触发如下错误:
ORA-00928: missing SELECT keyword
原执行的SQL语句如下:
INSERT ALL into COUNTRY ("CountryID","CountryName") values (1,'Germany') into COUNTRY ("CountryID","CountryName") values (2,'United Kingdom') into COUNTRY ("CountryID","CountryName") values (3,'United States') into COUNTRY ("CountryID","CountryName") values (4,'Russia') into COUNTRY ("CountryID","CountryName") values (5,'France') into COUNTRY ("CountryID","CountryName") values (6,'Pakistan') into COUNTRY ("CountryID","CountryName") values (7,'India') into COUNTRY ("CountryID","CountryName") values (8,'Brazil') into COUNTRY ("CountryID","CountryName") values (9,'Itly') into COUNTRY ("CountryID","CountryName") values (10,'Iran'), into COUNTRY ("CountryID","CountryName") values (11,'Austria') SELECT 1 FROM DUAL;
报错原因
- 核心触发原因是第10条插入子句末尾多了多余的逗号:Oracle的
INSERT ALL批量插入语法中,多个INTO子句之间不需要任何分隔符,直接顺序排列即可。这个多余的逗号会打断SQL解析器的语法识别逻辑,导致解析器无法定位到语句末尾要求的SELECT子句,最终抛出缺失SELECT关键字的错误。 - 补充说明:
INSERT ALL语法要求语句末尾必须搭配SELECT子句(通常写SELECT 1 FROM DUAL即可,原语句这部分写法是正确的,只是被多余逗号干扰导致识别失败)。
修正方案
删除第10条插入语句values (10,'Iran')后面的多余逗号即可,修正后的可正常执行的SQL如下:
INSERT ALL INTO COUNTRY ("CountryID","CountryName") VALUES (1,'Germany') INTO COUNTRY ("CountryID","CountryName") VALUES (2,'United Kingdom') INTO COUNTRY ("CountryID","CountryName") VALUES (3,'United States') INTO COUNTRY ("CountryID","CountryName") VALUES (4,'Russia') INTO COUNTRY ("CountryID","CountryName") VALUES (5,'France') INTO COUNTRY ("CountryID","CountryName") VALUES (6,'Pakistan') INTO COUNTRY ("CountryID","CountryName") VALUES (7,'India') INTO COUNTRY ("CountryID","CountryName") VALUES (8,'Brazil') INTO COUNTRY ("CountryID","CountryName") VALUES (9,'Italy') INTO COUNTRY ("CountryID","CountryName") VALUES (10,'Iran') INTO COUNTRY ("CountryID","CountryName") VALUES (11,'Austria') SELECT 1 FROM DUAL;
注:原语句中'Itly'属于'Italy'(意大利)的拼写笔误,不属于语法报错范畴,可根据实际业务需求选择是否修正。
内容的提问来源于stack exchange,提问作者nado1122
相关产品推荐
相关产品推荐

