Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Auto incrementing key
chanakam2000_at_gmail.com wrote:
: Hi,
: Please help me,
: I'm new to oracle environment.
: I want to make a kind of auto generated primary key for my table.
: I can make auto key with sequences and triggers. But only numeric
: keys
: But i want the key with some character value.
: Ex : for student_id column my preffered value sequence is
: S-00001
: S-00002
: S-00003 ..... & so on
: I searched lot in internet. But could not find goood solution.
: Please give me some idea.
pseudo code - I doubt you really want this, but here goes anyway...
number x = my_sequence.next_value
string my_key = 'S-' || format_number('99999',x)
You need to read the docs for the real names and inputs of the various functions.
: If this is not possible please give me idea to generate sequence like
: 00001,00002,00003....
A sequence returns a number. How you format the number is up to you. Oracle has many functions that might help. Received on Sun Apr 09 2006 - 17:51:56 CDT