Dvir
Dvir

Reputation: 301

ORACLE - UPDATE using INSERT seq inside FORALL

I have an ORACLE DB. I'm trying to loop through an array using FORALL and inside that FORALL to insert into a table with TABLE.NEXTVAL and after that to update a foreign key of another table with the new TABLE.CURVAL but I know that it's impossible.

How can I implement it?

FORALL I IN 1 ..5
insert into tbl
    values (tbl_seq.NEXTVAL)
update foo set tbl_fk = tbl_seq.CURVAL where foo.id=I

Thanks

Upvotes: 0

Views: 145

Answers (1)

user8406805
user8406805

Reputation:

@Dvir, You can't do this, because here only first INSERT statement is part of FORALL. And hence you can only get the last value of sequence from CURRVAL. I would like to suggest you use FOR loop instead of FORALL.

Upvotes: 1

Related Questions