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: problem about Sequence

Re: problem about Sequence

From: Grinberg L. <leon_at_grant.kharkov.ua>
Date: Thu, 29 Oct 1998 10:33:47 +0200
Message-ID: <719971$4ad@grant.grant.UUCP>

EdwardAwad_at_webtv.net wrote in message <718s0h$lcu$1_at_nnrp1.dejanews.com>...
>If the application requires numbers that are exactly in sequence (e.g. 1,
2,
>3, 4, ...) then SELECT MAX(user_id) FROM registration is the best solution.

But keep in mind that two sessions can get one values of user_id. Therefore application must repeat SELECT max.. and INSERT... It's not simple and even not possible in some situations.

You may use next technique:

CREATE TABLE max_tables_id
 (table_name VARCHAR2(60,
  max_id NUMBER);

and then

SELECT max_id+1 INTO :new_max_id FROM max_tables_id  WHERE table_name='registration' FOR UPDATE OF max_id; ....
INSERT INTO registration (user_id,...) VALUES(:new_max_id,...

UPDATE max_tables_id SET max_id=:new_max_id  WHERE table_name='registration';

COMMIT; -- or rollback.

 Of course, other "inserting" sessions will wait commit or rollback. But you must choose - or locking and values without gaps, or no locking and gaps (i.e. using SEQUENCE). Received on Thu Oct 29 1998 - 02:33:47 CST

Original text of this message

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