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: How to generate unique document number ?

Re: How to generate unique document number ?

From: <frank.van.bortel_at_gmail.com>
Date: 13 Sep 2006 00:44:16 -0700
Message-ID: <1158133456.882902.78910@i3g2000cwc.googlegroups.com>

krislioe_at_gmail.com schreef:

> Hi All,
>
> We need to generate Document Number where there should be any gap, so
> that we cannot use sequence. For example : Invoice Number.
>

Why not? Do not use the cache on a sequence. It will minimise the risk of "loosing" numbers due to shutdown. However, there's no always the possibility of a user that decides to rollback the transaction, or an error may occur, causing the transaction to be rolled back.

> one possible approach like : Select MAX(InvoiceNumber)+1 from invoice,
> what if that table has millions of rows, is this reliable enough ?

Reliable - in what way? There's not one way you would be able to ensure you will not be missing numbers, AND have a scalable solution.

> How to avoid two user do the same query at same time that lead to
> dupplicate number ?
>

By locking the table - as I said: no way it's going to scale. By creating an autonomous transaction - still possible to get missing numbers.

Bottom line: use a sequence, and explain some numbers may be missing - write to a "missing" table as soon as the number gets issued, and remove when the transaction completes. Make the write to your "missing" table an autonomous transaction Received on Wed Sep 13 2006 - 02:44:16 CDT

Original text of this message

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