Generate unique ID based on records in table
I want to generate the unique ID based on records in the table.
Continue Reading This Article
Enjoy this article as well as all of our content, including E-Guides, news, tips and more.
CREATE SEQUENCE my_sequence START WITH 1 INCREMENT BY 1;Then create a trigger to automatically populate your table's column with the next number in the sequence:
CREATE TRIGGER my_tab_trig BEFORE INSERT ON my_table AS next_num NUMBER; BEGIN SELECT my_sequence.NEXTVAL INTO next_num FROM dual; :new.my_column := next_num; END; /When a user inserts a row of data into the table, Oracle will run the trigger which will set the column value to the next unique number in the sequence. Forgive me if the above code is not perfectly correct as I typed it all off the top of my head. But this is definitely enough to get you started.
Dig Deeper on Oracle database design and architecture
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.
Meet all of our Oracle Database / Applications experts
View all Oracle Database / Applications questions and answers
Start the conversation
0 comments