执行Insert all批量插入SQL时遇ORA-00903: invalid table name错误求助
问题排查与解决
错误原因
ORDER是Oracle的保留关键字(用于排序的ORDER BY子句),直接将它作为表名使用时,数据库会把它识别为关键字而非普通表名,因此抛出ORA-00903: invalid table name错误。
两种解决方式
方式一:修改表名(推荐)
将表名改为非保留字,比如ORDERS,这是最规范的做法,能避免后续其他语法冲突。修改后的SQL如下:
Insert all into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id) values (70001,150.5,'05-Oct-2012',3005,5002) into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id) values (70009,270.65,'10-Sep-2012',3005,5002) into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id) values (70002,65.26,'05-Oct-2012',3002,5001) into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id) values (70004,110.5,'17-Aug-2012',3008,5002) into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id) values (70007,948.5,'10-Sep-2012',3007,5002) select * from dual;
方式二:用双引号包裹表名(仅当无法修改表名时使用)
如果必须保留ORDER作为表名,需要用双引号将表名括起来,强制数据库将其识别为标识符。注意:Oracle中如果创建表时没有用双引号,表名默认是大写的,所以双引号里要写大写的"ORDER":
Insert all into "ORDER"(ord_no,purch_amt,ord_date,customer_id,salesman_id) values (70001,150.5,'05-Oct-2012',3005,5002) into "ORDER"(ord_no,purch_amt,ord_date,customer_id,salesman_id) values (70009,270.65,'10-Sep-2012',3005,5002) into "ORDER"(ord_no,purch_amt,ord_date,customer_id,salesman_id) values (70002,65.26,'05-Oct-2012',3002,5001) into "ORDER"(ord_no,purch_amt,ord_date,customer_id,salesman_id) values (70004,110.5,'17-Aug-2012',3008,5002) into "ORDER"(ord_no,purch_amt,ord_date,customer_id,salesman_id) values (70007,948.5,'10-Sep-2012',3007,5002) select * from dual;
内容的提问来源于stack exchange,提问作者VK Sanghani
相关产品推荐
相关产品推荐

