Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: User Sequence Numbers

Re: User Sequence Numbers

From: Hermann Angstl <hal_at_camline.com>
Date: Mon, 03 Feb 2003 09:42:13 +0100
Message-ID: <3E3E2B65.3C98F4BF@camline.com>


Karsten Farrell wrote:

> insert into child_table (parent_name,child_nr,...)
> select parent_name,
> (
> select decode(child_nr,null,1,max(child_nr)+1)
> from child_table
> where child_table.parent_name(+) = parent_table.parent_name
> )
> from parent_table

Maybe - but remember: i am using multiple sessions. And i fear that oracle makes no atomic transaction. For example the *substatements* might be executed in *parallel* in the different sessions.

Especially the "select decode(child_nr,null,1,max(child_nr)+1)" is critical.

Imagine the following execution sequence: assume child_nr = 5

Session 1: do subselect: select decode(child_nr,null,1,max(child_nr)+1) -> 6 Session 2: do subselect: select decode(child_nr,null,1,max(child_nr)+1) -> also 6
Session 1: insert into child_table (parent_name,child_nr,...) ... select parent_name, (... result from above ...)... Session 2: insert into child_table (parent_name,child_nr,...) ... select parent_name, (... result from above ...)...

So the vital question is: Does Oracle execute your statement ATOMIC ?

cu,
hal Received on Mon Feb 03 2003 - 02:42:13 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US