multitable inserts and sequences
Date: Wed, 26 Jun 2013 11:37:24 +0200
Message-ID: <51CAB654.9080804_at_mgm-tp.com>
Hello,
we have a situation where we are using NEXTVAL and CURRVAL in the same multi-table insert statement.
Basically this is something like this:
create sequence foo_seq;
create table foo (id integer primary key, some_data varchar(10));
create table bar (f_id integer not null references foo (id), other_data varchar(10));
insert all
into foo (id, some_data) values (foo_seq.nextval, data_one)
into bar (f_id, other_data) values (foo_seq.currval, data_two)
with data as (
select '1-one' as data_one, '1-two' as data_two from dual
union all
select '2-one', '2-two' from dual
union all
select '3-one', '3-two' from dual
)
select data_one, data_two
from data;
In reality the CTE is a bit more complicated, but the basic structure is the same. BAR is a temporary table which is used in later steps, and I only added the foreign key for this test in order to see any "problem" right away. In reality there is no FK between the temp table and the "foo" table.
Running the above statement, everything is inserted correctly.
As far as I can tell, the above situation is not listed under the section "Restrictions on Sequence Values" in the manual.
But I wonder if this usage of NEXTVAL and CURRVAL is guaranteed to work, or is this working by coincidence?
Regards
Thomas
-- http://www.freelists.org/webpage/oracle-lReceived on Wed Jun 26 2013 - 11:37:24 CEST