Re: How to generate unique document number ?




krislioe@xxxxxxxxx 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

.



Relevant Pages

  • Re: How to generate unique document number ?
    ... Do not use the cache on a sequence. ... transaction, or an error may occur, causing the transaction to ... get missing numbers. ... Using the example of an invoice. ...
    (comp.databases.oracle.server)
  • Re: Programmers unpaid overtime.
    ... "A polynomial is a mathematical expression involving ... And if terms are missing, or the exponents are out of sequence, the ... You all think I'm paranoid, ...
    (comp.programming)
  • Re: puzzle
    ... Determine the xor of the numbers 0...n, ... >) sequence. ... Determine the sum of the numbers 0...n, ... The difference of the two sums is the missing number. ...
    (comp.programming)
  • Re: Query to find amissing number
    ... Here I need to write a query to find out that number 7 is missing in the ... given sequence. ... giving you a quick way to determine if any gaps exist. ...
    (comp.databases.sybase)
  • Re: Float Types Used as Primary Key on SQL 2005
    ... I am working with single row which keeps track of sequence ... @NEXTSEQ FLOAT OUTPUT, ... @Err INT OUTPUT ... ROLLBACK TRANSACTION ...
    (microsoft.public.sqlserver.programming)