iSelfSchooling.com  Since 1999     References  |  Search more  | Oracle Syntax  | Free Online Oracle Training

    Home      .Services     Login       Start Learning     Certification      .                 .Share your BELIEF(s)...

 

. Online Accounting        .Copyright & User Agreement   |
    .Vision      .Biography     .Acknowledgement

.Contact Us      .Comments/Suggestions       Email2aFriend    |

 

Online Oracle Training for beginners and advanced - The most comprehensive Oracle tutorial

The authors do not guarantee or take any responsibility for the accuracy, or completeness of the information.

 

 

 

 

 

 

 

Lesson 33

"The soul is not where it lives but where it loves."

-Thomas Fuller (1608-1661)

How to use the “WHEN-VALIDATE-ITEM” trigger?

 

Your client has a form that contains an item that holds a value for the “COMM-PAID-YTD” column (Commission Paid Year To Date). They want to validate the data in that column to be between 200 and 800 dollars. Anything else, it must give the following error messages:

If the commission is less than 200 then a message should be displayed as:

                ERROR: Commission must be at least $200.00 or more.

If the commission is more than 800 then a message should be:

                ERROR: Year to date commission can not exceed $800.00.

You as a programmer, asked to write a trigger to check the field item and send an error message to a user if the data entered was violated by above rules.

 

Solution:

=========

Assuming that you have a form that created by the “CUSTOMERS” table and there is an item called “COMM_PAID_YTD.”

 

1- Go to the object navigator window and expand the “COMM_PAID_YTD” item.

 

2- Highlight the “Trigger” item and click on (+) the “Create” icon.

 

3- Select the “WHEN-VALIDATE-ITEM” trigger.

 

3- Write the following procedure: 

 

IF :comm_paid_ytd < 200 THEN

    -- Must be at least $200.

    message('ERROR: Commission must be at least $200.00 or more.');

    display_error;  -- Display the message box

    raise form_trigger_failure; -- to keep the cursor in the item

ELSIF :comm_paid_ytd > 800 THEN

    -- Not more than $800.

    message('ERROR: Year to date commission can not exceed $800.00.');

    display_error; -- Display the message box

    raise form_trigger_failure;          -- to keep the cursor in the item

END IF;

 

4- Compile and close the trigger.

 

5- Run the form, go to the “COMM-PAID-YTD” item, and enter an invalid value such as 900 or 50.