简体   繁体   中英

Insert multiple records in oracle

I am using oracle sql developer to insert rows in my database.

While this request is working :

INSERT INTO TABLE ( USERID, USERNAME) VALUES (1,"ok1")

The second one (when I am trying to insert multiple rows)is not working:

INSERT INTO TABLE ( USERID, USERNAME) VALUES (1,"ok1"),(2,"ok2")

I am getting this error :

Erreur SQL : ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"

You could use INSERT ALL statement. For example:

INSERT ALL
  INTO mytable (column1, column2, column3) VALUES ('val1.1', 'val1.2', 'val1.3')
  INTO mytable (column1, column2, column3) VALUES ('val2.1', 'val2.2', 'val2.3')
  INTO mytable (column1, column2, column3) VALUES ('val3.1', 'val3.2', 'val3.3')
SELECT * FROM dual;

Oracle does not support multi-row inserts. You need to write one insert per row:

INSERT INTO TABLE ( USERID, USERNAME) VALUES (1,'ok1');
INSERT INTO TABLE ( USERID, USERNAME) VALUES (2,'ok2');

Additionally: string literals need to be enclosed in single quotes in SQL. Double quotes are for identifiers. "ok1" is a column name, 'ok1' is a string constant.

有关输入测试数据的其他一些方法,请参阅最近的帖子: 多次插入相同的数据

If you are not worried about SQL injection then run the following :

BEGIN
INSERT INTO TABLE ( USERID, USERNAME) VALUES (1,'ok1');
INSERT INTO TABLE ( USERID, USERNAME) VALUES (2,'ok2');
END;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM