5 pts.
 To increase number and combine data using sql
hi,

I want to create a sql that generate a number of 4 digits with combination of character input.The number will increase if it is new record.

for example :

category = 'P'

so the output will be :  P-0001

for the next record the output will be : P-0002

any ideas?

thanks.

 



Software/Hardware used:
TOAD for ORACLE, All Oracle Products
ASKED: August 16, 2010  3:39 AM
UPDATED: September 22, 2010  2:23 PM

Answer Wiki:
Maybe more details would have been needed here. A decision on how to get the numbers for new records should be made, as there are many options. You could use a sequence, or you could issue a SELECT max() query, or you could store the number from the last record in another table and update it after each insertion, etc. Using a sequence, it would be something similar to this: <pre>SELECT category || '-' || TO_CHAR(your_sequence.nextval,'fm0000') FROM ... WHERE...;</pre>
Last Wiki Answer Submitted:  September 22, 2010  2:23 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _