如何使用一个insert语句将多行插入oracle数据库?

时间:2013-01-21 14:54:54

标签: sql oracle10g sql-insert

  

可能重复:
  Best way to do multi-row insert in Oracle?

我有这个插入语句

INSERT INTO mytable VALUES 
('val1', 'val2'),
('aa',   'cc'),
('ww',   'dd');

我收到了这个错误 ORA-00933:SQL命令未正确结束

1 个答案:

答案 0 :(得分:17)

你正在使用oracle,试试这个

INSERT ALL 
    INTO mytable ("id", "name")
         VALUES ('val1', 'val2')
    INTO mytable ("id", "name")
         VALUES ('aa', 'cc')
    INTO mytable ("id", "name")
         VALUES  ('ww', 'dd')
SELECT * FROM dual  ;

或简单

INSERT INTO mytable ("id", "name") VALUES ('val1', 'val2');
INSERT INTO mytable ("id", "name") VALUES ('aa', 'cc');
INSERT INTO mytable ("id", "name") VALUES ('ww', 'dd');