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

Home -> Community -> Usenet -> c.d.o.server -> Is this safe???

Is this safe???

From: Chris Forlano <cforlano_at_nortelnetworks.com>
Date: Sun, 26 Sep 1999 23:00:20 +0100
Message-ID: <37EE9774.AF71ECD8@nortelnetworks.com>


Does the following procedure guarantee atomicity for the id_generator table?
What I mean to say is, how can I guarantee that no one else will be able to
update the id_generator table at the same time this function is running?

If not, how can I guarantee it?
Can I do this as a function?

create or replace
PROCEDURE generate_id( type_in in varchar2, id_out out varchar2 ) AS
  CURSOR id_cursor IS
    SELECT prefix, next_id FROM id_generator WHERE type = type_in;   prefix varchar2(20);
  next_id number(9);
BEGIN   OPEN id_cursor;

/* Get the next available id. */

  FETCH id_cursor INTO prefix, next_id;

/* Update to the next available id. */
  UPDATE id_generator SET next_id = next_id + 1 WHERE type = type_in;

/* Create an id containing a prefix and id (ex, TST000123). */
  id_out := CONCAT( prefix, LPAD( TO_CHAR( next_id ), 9, '0' ) );

  CLOSE id_cursor;

END generate_id;

I'm running Oracle 8.0.5 on Solaris 2.6.

Thanks,

Chris

--
Chris Forlano
Automation Development
Nortel Networks, Maidenhead
590 4342 (01628 434 342)
cforlano_at_nortelnetworks.com Received on Sun Sep 26 1999 - 17:00:20 CDT

Original text of this message

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