In a Oracle database table, how are auto incremented sequence values done with PL/SQL such as for a key value or id typed columns?
Included is a discussion on sizing table resources based on what you know about the projected growth of all the related tables in a given schema. How many piano tuners are there in the city of Chicago? Probably less than the population of the city altogether... :) and so on.
Know your data.
How do I do that? Read on.
Using Database Triggers to Auto Increment Column Values
One possible approach is to use database triggers. The values are ensured unique through the implementation of sequence typed database objects.
In the example above, the table
FUNDRAISER
has an associated sequence calledFUNDRAISER_SEQ
for a primary key value.The Parts List: What you need for the example.
This is an older sample of code, but it the
Construct was what we did with older releases of the Oracle Database. Release 11g changes that so that sequence increments can be assigned directly to a PL/SQL variable or a SQL statement call. Both will work.
Challenge yourself to figure out what the revised PL/SQL might look like...
The notation is:
FUND_ID
is the column that is ignored in the insert statement. The starting value of each sequence is 20. A call to theSEQ.NEXTVAL
value increments the sequence by the amount identified in the sequence declaration.A Brief Discussion on Sequence Sizing
If you spec a sequence without a MAXIMUM value, the system assigns the largest possible integer handled by the database, which is 20+ digits long.
Consider looking at the original project design I have worked with on Google Code: Google Code Project: Fundraiser Organizer
A look at the first screenshot shows my estimates. This project started out as a sheet of data to keep track of an fund raising drive. Hope you find it informative and thought inspiring!
The UI and my testing efforts were conducted on a public demo site hosted by Oracle at Oracle Apex Demo System