Best Way to Generate Unique and consecutives numbers in Oracle

Posted by RRUZ on Stack Overflow See other posts from Stack Overflow or by RRUZ
Published on 2009-12-31T16:39:09Z Indexed on 2010/04/25 13:43 UTC
Read the original article Hit count: 269

Filed under:
|
|

I need to generate unique and consecutive numbers (for use on an invoice), in a fast and reliable way. currently use a Oracle sequence, but in some cases generated numbers are not consecutive because of exceptions that may occur.

I thought a couple of solutions to manage this problem, but neither of they convincing me. What solution do you recommend?

  1. Use a select max ()

    SELECT MAX (NVL (doc_num, 0)) +1 FROM invoices
    
  2. Use a table to store the last number generated for the invoice.

    UPDATE docs_numbers
        SET last_invoice = last_invoice + 1
    
  3. Another Solution?

© Stack Overflow or respective owner

Related posts about Oracle

Related posts about plsql