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.
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:
The stored procedure (actually: a function)
testing