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 -> Re: Re: Re: Sequence Number Re-use is it possible, what is the standard

Re: Re: Re: Sequence Number Re-use is it possible, what is the standard

From: Spencer <spencerp_at_swbell.net>
Date: Fri, 9 Mar 2001 22:22:01 -0600
Message-ID: <mZhq6.129$8n2.153188@nnrp3.sbc.net>

if a "bid" is a "bid" when you assign a unique number, and it is "tracked" in the system, then perhaps the unique number shouldn't be reused for another "bid".

it may be that your client is in need some education as to the purpose of a unique identifer. the number isn't unique if it's used again for another "bid".

an Oracle SEQUENCE is specifically designed to NOT return a duplicate number.

the SEQUENCE is implemented to meet the requirement for multiple processes to obtain unique numbers (usually used as identifiers), without having to serialize access to (i.e. obtain a lock on) a single database object.

if your system requirement is for something other than a unique number, then a SEQUENCE may not be the best option to meet that requirement.

if you insist on using a sequence, but also reusing the numbers, then you may find that you need to store the "returned" bid numbers in a "reuse pool" (implemented as a table). processes that need a number from the "reuse pool" will need to obtain an exclusive lock on a row in the table before deleting it from the "reuse pool".

you could try creating a table and a package to make this work. here is a rough outline, there are some areas that need improvement, like handling of oracle exceptions that may be raised (e.g. ORA-00054) but it's a start

CREATE TABLE bidno_reuse
(BIDNO NUMBER(38)
,CONSTRAINT bidno_reuse_pk
 PRIMARY KEY (BIDNO)
);

CREATE OR REPLACE PACKAGE my_package IS
FUNCTION get_bidno RETURN NUMBER;
PROCEDURE return_bidno (ln_bidno IN NUMBER); END my_package;
/

CREATE OR REPLACE PACKAGE BODY my_package IS

FUNCTION get_bidno RETURN NUMBER
IS
  ln_bidno NUMBER(38);
  CURSOR lcsr_reuse IS
  SELECT r.ROWID, r.BIDNO
    FROM bidno_reuse r
   WHERE ROWNUM=1
  FOR UPDATE NOWAIT;
  lrec_reuse lcsr_reuse%ROWTYPE;
BEGIN
  OPEN lcsr_reuse;
  FETCH lcsr_reuse INTO lrec_reuse;
  IF lcsr_reuse%NOTFOUND THEN
    SELECT bidno_sequence.NEXTVAL

      INTO ln_bidno
      FROM DUAL WHERE ROWNUM=1;

  ELSE
    ln_bidno := lrec_reuse.BIDNO;
    DELETE FROM bidno_reuse
     WHERE ROWID = lrec_reuse.ROWID;
  END IF;
  CLOSE lcsr_reuse;
  COMMIT;
  RETURN ln_bidno;
EXCEPTION
  WHEN OTHERS THEN
    ROLLBACK;
    RAISE;
END get_bidno;

PROCEDURE return_bidno (ln_bidno IN NUMBER) IS
BEGIN
  INSERT INTO bidno_reuse (BIDNO) VALUES (ln_bidno);   COMMIT;
END return_bidno;
END my_package;
/

from your application, get bid numbers using an anonymous PL/SQL block. if using Pro*C, for example, like this:

EXEC SQL EXECUTE
  begin
    :my_bidno := my_package.get_bidno;
  end;
END-EXEC; and return bid numbers to be reused like this:

EXEC SQL EXECUTE
  begin
    my_package.return_bidno(:my_bidno);
  end;
END-EXEC; <u28656005_at_spawnkill.ip-mobilphone.net> wrote in message news:r.983804783.1236785888@[208.50.67.66]...
> Dear Spencer,

>

> In your posting Re: Re: Sequence Number Re-use is it possible, what is
> the standard from Sat, 3 Mar 2001 17:58:54 -0600 you write:
>

> >
> > have you considered postponing the assignment of the
> > unique sequence number until a row is actually inserted
> > into the table? i'm thinking that your "problem" could be
> > resolved with a small change to the application design.
> >
> > a "bid" isn't really a "bid" until it is "saved", so it doesn't
> > really make sense to acquire and assign a unique key
> > until it is inserted into the table.
> >

>
> Actually a bid is a bid even before it is entered into the program. We
 enter it
> into the system to track it. And they need to see the bid number first,
 that
> was one of their requirements.
>

> But thanks for the suggestion, and the reply.
>

> Mark
>
>
>
>
>
>
>

> --
> Spam protected message from:
> Sent by mspritzler from sasco within area com
> Posted via http://www.usenet-replayer.com/cgi/content/new
> Received on Fri Mar 09 2001 - 22:22:01 CST

Original text of this message

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