You are on page 1of 2

Oracle Forms Triggers

Trigger is a set of statements that executed when an action take a place.


There is some types depends on event level (Form, Block, Record, Item) for Triggers, if the same
trigger found in more than one level then the lowest level will run ex: when_validate_item on (form,
block, item) then only the item level will run. The second types of triggers depends on the time for run
(pre, when, post, on, custom) each type is different from other in time to run.
Pre: before the chosen event ex: pre_query (before execute the query).
When: during the event ex: when_validate_item (when item data validation).
Post: after the event ex: Post_Query (after execution of query).
On: this type unpredictable cause we don’t know when it will run, may during a trigger execution or
just when you try to enter data in protected field.
Custom: you can add a custom trigger and call it from any were (execute_trigger(‘custome_tri’);)

Here are some of the most important trigger can the programmer use in any program:

trigger exe purpose level ex


1 When_new_form_instance 1 To initial some form :global.datetime:=sysdate;
variable values :time_text:=sysdate;
:user_text:=user;
2 On_error 1 To handle error during form If error_code = 14015 then
run time, or to display Message(‘‫ الكتابة في هذا الحقل‬D‫;)’ال يمكنك‬
it in good way to user. Message(‘‫ الكتابة في هذا الحقل‬D‫;)’ال يمكنك‬
End if;
3 Pre_insert, pre_update 1 To set some fields Form, :username := user;
value implicitly in Block
code.
4 Post_query Return To get description for Block Select ename into :name_txt
rows code field. From emp where empno=:empno;
5 Pre_query 1 To set default where to block Set_block_property
block (‘block1’,default_where,’deptno=1’);
6 When_new_record_instance 1 To set initial values to block Select max(empno)+1 into :empno
block items when add From emp;
new record.
7 When_validate_item 1 To get description for item Select ename into :name_txt
the code entered in From emp where empno=:empno;
item.
8 Post_change 1 Executes only when item Select ename into :name_txt
item value is changed. From emp where empno=:empno;
**Note: we preferred
When_validate_item, cause it’s
execute every time in item.
9 Key_next_item 1 Executes when you item Select ename into :name_txt
press enter-key after From emp where empno=:empno;
entered value in item. **Note: it’s executes instead of
going to the next item (:name_txt).
10 When_button_pressed 1 Executes when mouse item Message(‘clicked’);pause;
click or by keyboard **Note: set property MOUSE
enter-key. NAVIGATE to NO
11 When_checkbox_changed 1 When you change the item If :box = 1 then
selection of radio, Message(‘open’);
checkbox. End if;

System Variables
1 : System.current_block Get the current block.
2 : SYSTEM.current_item Get the current item.
3 :System.block_status New, enter-query, changed

You might also like