I\'m looking for a good way to perform multi-row inserts into an Oracle 9 database. The following works in MySQL but doesn\'t seem to be supported in Oracle.
This works in Oracle:
insert into pager (PAG_ID,PAG_PARENT,PAG_NAME,PAG_ACTIVE)
select 8000,0,'Multi 8000',1 from dual
union all select 8001,0,'Multi 8001',1 from dual
The thing to remember here is to use the from dual
statement.
(source)
If you have the values that you want to insert in another table already, then you can Insert from a select statement.
INSERT INTO a_table (column_a, column_b) SELECT column_a, column_b FROM b_table;
Otherwise, you can list a bunch of single row insert statements and submit several queries in bulk to save the time for something that works in both Oracle and MySQL.
@Espo's solution is also a good one that will work in both Oracle and MySQL if your data isn't already in a table.
you can insert using loop if you want to insert some random values.
BEGIN
FOR x IN 1 .. 1000 LOOP
INSERT INTO MULTI_INSERT_DEMO (ID, NAME)
SELECT x, 'anyName' FROM dual;
END LOOP;
END;