To increase number and combine data using sql

5 pts.
Tags:
Oracle
SQL
SQL Data Set
TOAD
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

Thanks. We'll let you know when a new response is added.

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>

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following