Topics: Hands-On 10 – Sequence object, Trigger
(pre-insert)
Generate a unique
customer ID and assign it to each new customer that is added to a table.
Your client
requires to find what last customer ID was entered into their system, then
she/he increment it by 1 and use that number. This is not very professional
way of doing business specially if you have multiple transactions to enter
data.
You have been
assigned, to add a sequence number to custid starting with 200 and incremented
by 1. So, your customer ID would start from 200, 201, 202, and so on.
In this
Hands-On, you will learn how to: create sequence object, create and use
"PRE-INSERT" trigger.
|
More Resources by
Google: |
|
|
|
|
Save the Form name
as version 10.
Create a sequence
number to increment the customer id number when you insert a new customer.
Go to MS-DOS
Prompt.
Login to “sqlplus”
as “iself” password “schooling.”
Create a sequence
object that starts from 200 and is incremented by 1.
Use the “Next
Value” Function to increment the sequence number.
Repeat to run the
query.
Close the MS-DOS
window or minimize it.
Open the "custid"
property palette.
Change the
"Required" property to "NO."
Create a
"PRE-INSERT" trigger for the “Customer” data block.
Type “P” and “R,”
and then select the trigger.
Write a select
statement to assign a new sequence number to “custid.”
Compile the trigger
and then close the window.
Run the
application.
Click “Execute
query.”
Navigate through
the customers information.
Click on the
"insert" icon.
Now, the form is on
the “insert” mode.
Type the new
customer information.
Remember that the
“Customer ID” is going to be generated.
Save the record.
New “Customer ID"
was generated.
Add more customers.
Duplicate the
previous record.
Notice that even
though the Customer ID is copied, the new "Customer ID" will be assigned to it.
Click on "save."
Notice that
"custid" is changed to the new number (205).
Navigate through
the application.
Then, close the
application and save the changes.
Now, you should
practice this over and over, until you become a master at it.
Good Luck.
|