Skip to content
Advertisement

Multiple Sequence in SQL Oracle / Varchar2 ID with letters and digits

I am trying to ‘generate’ a Varchar ID that contains letters and digits too with a sequence, but I think there will be more sequences than one.

What I am looking forward to is something like this ‘DJ_Digit_Digit_Letter_Letter_Letter’. An example would be DJ00WVX/DJ01HYZ/DJ99ZZZ. This is also my primary key so it would be good if I could not encounter any primary key errors.

I thought about working in ascii so I will generate numbers between 65 and 90 (A-Z) and Insert them into the column. Same for the numbers in ascii 45 to 57 or something like that. I don’t know how I could use more sequences on the same column like ‘letter_seq.nextvalue,digit_seq.nextvalue’, i know that this example is wrong, but it was easier for me to explain it. Maybe all my thinking is wrong

In conclusion I need to get something that starts with DJ followed by 2 digits and 3 letters, all wrapped up in a primary key. It’s ok to get like 20-30 unique entries, I think.

Thank you for your help!

Advertisement

Answer

To me, it looks like this:

Several sample values:


However, if

It’s ok to get like 20-30 unique entries, I think.

means that you need to generate at most 30 values, well, you’d easily create them manually; why would you develop any software solution for that? If you started typing, you’d be over by now.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement