Created an Oracle Form to handle specific events / triggers like When-New-Form-Instance, Pre-Insert, Post-Insert, Pre-Update, Post-Update, Post-Query and Post-Forms-Commit.
I am doing the following simple tasks on these events to give you an example:
Picking up Oracle Session ID through USERENV function and User to display below the title of the form, the following is the code written:
SELECT 'ORACLE SESSION ID: '
|| USERENV ('SESSIONID')
|| ' USER NAME: '
Post-Query TriggerPopulating the Department Name.
WHERE department_id = :scott_emp.deptno;
Pre-Insert TriggerChecking if the Hiredate is current date or not.
IF :SCOTT_emp.HIREDATE <> TRUNC (SYSDATE)
:VAL_PRE_INSERT := 'Hire Date must be current date.';
-- else ok
:VAL_PRE_INSERT := 'Hire Date is valid.';
Post-Insert TriggerCounting total number of employees in table.
SELECT 'Employee Count After: ' || COUNT ( * )
Pre-Update TriggerChecking if current day is Sunday then stopping the user the update the record.
IF TO_CHAR (SYSDATE, 'DAY') = 'SUN'
:VAL_PRE_UPDATE := 'Update is not allowed on Sundays';
:VAL_PRE_UPDATE := 'Update is allowed today.';
Post-Update TriggerJust giving a simple message.
:VAL_POST_UPDATE := 'You updated ' || :scott_emp.ename || '''s record.';
Post-Forms-Commit TriggerDisplaying Date and Time of Last Commit
'Last Commit executed on '
|| TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS');
The following is the screen shot of this form and source code(Table's Script and FMB file) can be download from the following link: Form_Triggers.Zip
Oracle Forms Recipes eBookDownload