> > > > > Better? Maybe. Consider. > > > > Your program connects via SQL*net to the DB. At insert time, > > you need to fetch a sequence, so you issue 'select > > seq.nextval from dual'. Seems harmless enough until ... > > > > 1. The select statement must be passed across the SQL*Net > connection. > > 2. The statement must be parsed. Maybe the worst you will > have here > > is a soft parse, but non the less, you are using the CPU for this. > > 3. The statement is executed and the fetch occurs. > > 4. The result is passed back to your program. > > 5. You bind the value (hopefully) to your statement handle. > > 6. You then execute the insert statement. > > > > If you use a BEFORE INSERT trigger to fetch the sequence, you > > will eliminate steps 1, 2, 3, 4, 5 from the flow. > > > > Great point. I think I will stay with the Before insert trigger. >
And, newer versions of Oracle SQL support Returning XXX into :1, so you can bind :1 as an in/out parameter and get the value you need back out in the same step, assuming you need it ;) Jeff
