Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert multiple records in oracle [duplicate]

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"
like image 844
user2443476 Avatar asked Oct 16 '25 16:10

user2443476


2 Answers

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;
like image 193
Lalit Kumar B Avatar answered Oct 19 '25 06:10

Lalit Kumar B


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.