Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:09:27+00:00 2026-06-03T02:09:27+00:00

I need to generate a unique serial number in our web application. I have

  • 0

I need to generate a unique serial number in our web application.

I have created a table called SerialNumber which will have only one row. In the begining it will have value like ‘0000000000’ ten times zero. This will be incremented by one every time a serial number needs to be generated.

e.g. 0000000001, 0000000002 and so on.

I have kept the column datatype as Integer which stores values as 0, 1, 2 etc and not as 0000000001. I want the serial number to be ten digits only with zeros appended at the begining.

Please help me to write the stored proc for this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:09:29+00:00Added an answer on June 3, 2026 at 2:09 am
    select to_char(<column-value>, 'FM0000000000') from serialNumber;
    

    I don’t know what’s behind your requirement, but most probably, you are better served with a sequence. Using a table to generate unique ids is usually a poor choice that should be reviewed.

    As for a stored procedure along with a sequence, a basic frame to build upon could be:

    The sequence:

    create sequence serial_number_seq;
    

    The stored procedure (actually: a function)

    create or replace function next_serial_number return varchar2 as
    
           serial_number_ number;
           MAX_SR_NO number;
    begin
    
           select serial_number_seq.nextval into serial_number_ from DUAL;
    
           Select MAX(sr_no) INTO MAX_SR_NO from serialNumber;
    
           serial_number_ := GREATEST(serial_number_, MAX_SR_NO); 
    
           return to_char(serial_number_, 'FM0000000000');
    
    end    next_serial_number;
    /
    

    testing

    begin
      dbms_output.put_line(next_serial_number);
      dbms_output.put_line(next_serial_number);
      dbms_output.put_line(next_serial_number);
      dbms_output.put_line(next_serial_number);
      dbms_output.put_line(next_serial_number);
      dbms_output.put_line(next_serial_number);
    -- in the place where you use the serial number the greatest 
    --  of inserted value from external system or sequence value will be used
     final_value:= next_serial_number;
    end;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For an application I need to generate unique serial numbers for each English word.
I have a project in which I need to generate a unique 5 digit
I need my application to use client's phone-number to generate unique ID for my
I need to generate invoices in large batch which will be transformed to EDI
I need to generate unique ID's for my application. When I used (UUID.randomUUID()).toString() ,
I need to generate a unique string that will differ from machine to machine
I need to generate a unique integer id for a string. Reason: I have
I have a table called SharedNumber , which has only one field - an
I need to generate an unique number of 32 bits in Java. I need
I need to generate a nine digit numeric code (random preferably) which is unique

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.