This is the query i have used for insert multiple rows in oracle database. But when am using sequence within it it raises error as ORA-00001: unique constraint. How to do it.
INSERT ALL
INTO POSTAL_CODE( postal_code,desc)
VALUES(postal_code.NEXTVAL,'Coimbatore')
INTO POSTAL_CODE (postal_code,desc)
VALUES(postal_code.NEXTVAL,'Mumbai') SELECT * FROM DUAL;
The restrictions on multitable inserts include:
That isn't quite true - you can use a sequence, it just always gets the same value, so it can be useful to create parent and child records in one go by referring to the same sequence.
If you want to continue to use
insert all
you could work around that by using a non-deterministic function that gets the sequence value:But that's a bit awkward. You're probably better off using individual insert statements - using a multitable insert into a single table isn't really gaining you much anyway - or a trigger to set the unique column from the sequence, or a CTE/inline view to generate the values to insert.