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 -> HowTo - create user defined sequence with proper serialization

HowTo - create user defined sequence with proper serialization

From: <p.santos000_at_gmail.com>
Date: 29 Aug 2006 08:57:07 -0700
Message-ID: <1156867027.800262.303070@i3g2000cwc.googlegroups.com>


Folks,
  Here is a difficult question that I'm hoping you can help me solve.

  Requirements:

 Example: (GROUPS table)

ACCOUNT_ID NAME SEQ
======= ===== =====
 347164311 GROUP1 1
 347164311 GROUP2 2
 347164311 GROUP2 4

The key thing here is serialization and I'm not sure how to achive this.
Here is the sample function that delivers the next available sequence, but
doesn't yet serialize access to it.

CREATE OR REPLACE FUNCTION GET_SEQ (ACCTID NUMBER) RETURN NUMBER IS
i NUMBER := 0;
two_power_i NUMBER := power(2,i);
curr_mask groups.seq%TYPE;

CURSOR masksCursor IS SELECT seq FROM groups WHERE account_id = acctid ORDER BY seq;

BEGIN
OPEN masksCursor;
LOOP
FETCH masksCursor INTO curr_mask;
EXIT WHEN curr_mask != two_power_i OR masksCursor %NOTFOUND; i := i + 1;
two_power_i := power(2,i);
END LOOP;
CLOSE masksCursor;
RETURN two_power_i;
END;
/

Any idea on how to make the above function serial so that if 2 concurrent users execute the function, they don't both get the same value?

-peter Received on Tue Aug 29 2006 - 10:57:07 CDT

Original text of this message

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