I would like to use alpha-numeric format for primary key, that is A1 A2 A3 and have it auto increment.
How can i do that? is it even recommendable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’d need to create a SEQUENCE:
Then, you use:
If you want that alphanumeric value to increment as well, create another sequence & use the CHR function:
But my recommendation would be to make this column your surrogate key, and use the sequence value for the actual primary key column:
…because
VARCHAR2will take more bytes thanNUMBER. It’ll make a difference when JOINing tables, and allow the flexibility to change the surrogate key without impacting referential integrity (IE: B1, B2, B3…).