I am using Oracle 12c. I have a table with an auto increment column, pk_id
. For a single row insert I do this:
insert into mytable (colA, colB) values (1,2);
It works. The primary key column pk_id
is auto generated.I found how to insert multiple rows in one go here. So I tried this to do batch insert:
insert all
into mytable (colA, colB) values (2,4)
into mytable (colA, colB) values (3,6)
into mytable (colA, colB) values (4,8)
into mytable (colA, colB) values (5,10)
select 1 from dual;
But it is showing this error:
An UPDATE or INSERT statement attempted to insert a duplicate key
How can I do batch insert?
EDIT: The table definition:
CREATE TABLE MYTABLE
(
PK_ID NUMBER(11) GENERATED ALWAYS AS IDENTITY INCREMENT BY 1 START WITH 1 NOT NULL
, COLA NUMBER(8) NOT NULL
, COLB NUMBER(8) NOT NULL
, CONSTRAINT MYTABLE_PK PRIMARY KEY
(
PK_ID
)
ENABLE
);