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: 363
        
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?
Use a select max ()
SELECT MAX (NVL (doc_num, 0)) +1 FROM invoicesUse a table to store the last number generated for the invoice.
UPDATE docs_numbers SET last_invoice = last_invoice + 1Another Solution?
© Stack Overflow or respective owner