0

I can insert one row in a table using this code:

INSERT INTO SCHEME.TABLE
    (col1, col2)
VALUES ('val1', 'val2');

I need to insert several rows in a table.

To insert several rows, i've tried:

INSERT INTO SCHEME.TABLE
    (col1, col2)
VALUES ('val1', 'val2'),
VALUES ('val1', 'val2');

INSERT INTO SCHEME.TABLE
    (col1, col2)
VALUES ('val1', 'val2'),('val1', 'val2');

and some other variations. Niether of them worked :(

Ladenkov Vladislav
  • 1,247
  • 2
  • 21
  • 45

1 Answers1

2

You need an INSERT statement for each row to insert, like :

INSERT INTO SCHEME.TABLE (col1, col2) VALUES ('val1', 'val2');
INSERT INTO SCHEME.TABLE (col1, col2) VALUES ('val3', 'val4');

Or you can use the INSERT ALL construct (but you still need to repeat the table name each time, and you need to finish your statement with some kind of select) :

INSERT ALL
    INTO SCHEME.TABLE (col1, col2) VALUES ('val1', 'val2')
    INTO SCHEME.TABLE (col1, col2) VALUES ('val3', 'val4')
SELECT 1 FROM DUAL;
GMB
  • 216,147
  • 25
  • 84
  • 135
  • if i have thousands of rows to insert, and i send them from python process, will multiple INSERT operation be slower than solution from duplicated question? – Ladenkov Vladislav Nov 29 '18 at 19:52
  • Just found out about the « INSERT ALL » statement in Oracle, and updated my answer accordingly – GMB Nov 29 '18 at 20:06