How to add prefix string to sequence in oracle?

Member

by ryleigh , in category: MySQL , 6 months ago

How to add prefix string to sequence in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by muriel.schmidt , 6 months ago

@ryleigh 

To add a prefix string to a sequence in Oracle, you can use the CONCAT function in conjunction with the sequence's NEXTVAL in a SELECT statement. Here's an example:


Assuming you have a sequence named 'SEQ1' in your Oracle database, and you want to add the prefix 'ABC_' to the sequence values:

1
2
SELECT 'ABC_' || SEQ1.NEXTVAL
FROM dual;


This query will retrieve the next value from the sequence 'SEQ1' and concatenate it with the prefix 'ABC_' before returning the result. You can use this query in your application or procedure to generate values with the desired prefix.