I want to insert new values to an Oracle table. The table is quite large and the ID codes are stored as numbers. I’d like to write insert statements that can add my new information and assign an ID automatically which isn’t already taken.
For example:
insert into example_table values
(
(select max(person_id)+1 from example_table),
99, 'example name', 'example type');
But this code above obviously wouldn’t work, because I am specifying an ID (99). If I set 99 to null in the above code snippet, will it then work? Not sure how to format.
Thanks.
you can do this by defining a sequence and trigger on the database table.
The sequence will simply vend id’s in sequential order. The trigger will fire when the row is inserted and ask the sequence for the next available id , which it will then put into the table for you.. This way, passing NULL will work ok..