This section describes the triggers that Oracle Forms creates when you define a master-detail relation. The example trigger text shown with each trigger description shows the basic structure of the trigger. The actual trigger text that you will see in your own forms will be application-specific, and may look somewhat different.
(If specific triggers already exist for the master block, those existing triggers are used, and Oracle Forms does not create new, additional ones.)
Oracle Forms also creates user-named procedures that are called by master-detail triggers.
Oracle Forms generates comments in the default trigger and procedure code. Comments are denoted by the standard PL/SQL double-hyphen ('- -').
Every master-detail relation must have an On-Clear-Details trigger. It fires during the clear phase of coordination, and clears all of the detail records in the detail block. This trigger calls the CLEAR_ALL_MASTER_DETAILS procedure, as shown in the following example trigger text:
-- Begin default relation program section
--
Clear_All_Master_Details;
--
-- End default relation program section
Oracle Forms creates the On-Check-Delete-Master trigger when the Delete Record Behavior property is set to Non-Isolated. It fires when there is an attempt to delete a master record. The trigger queries the database to see if detail records exist for the master record. If no details exist, the trigger deletes the master record. If detail records are found, the trigger displays the message:
Cannot delete master record when matching detail records exist.
as shown in the following example trigger text:
--
-- Begin default relation declare section
--
Declare
Dummy_Define char(1);
--
-- Begin B detail declare section
--
cursor B_cur is
select null from MASDET
where PARENT = :A.ID;
--
-- End B detail declare section
--
--
-- End default relation declare section
--
--
-- Begin default relation program section
--
Begin
--
-- Begin B detail program section
--
Open B_cur;
Fetch B_cur into Dummy_Define;
if ( B_cur%found ) then
Message('Cannot delete master record when matching
detail records exist.');
Close B_cur;
raise Form_Trigger_Failure;
end if;
Close B_cur;
--
-- End B detail program section
--
End;
--
-- End default relation program section
Oracle Forms creates a On-Populate-Details trigger for every master-detail
relation. It fires during the population phase of block coordination. The trigger
first checks the status of the master record and the value of its primary-key
field, then navigates to the detail block to issue the appropriate query. This
trigger calls the QUERY_MASTER_DETAILS procedure, as shown in the following
example trigger text:
--
-- Begin default relation declare section
--
Declare
recstat char(20) := :system.record_status;
relation_id relation;
--
-- End default relation declare section
--
--
-- Begin default relation program section
--
Begin
if ( recstat = 'NEW' or recstat = 'INSERT' ) then
return;
end if;
--
-- Begin B detail program section
--
if ((:A.ID is not null)) then
relation_id := find_relation('A.AB');
Query_Master_Details(relation_id, 'B');
end if;
--
-- End B detail program section
----
End;
Oracle Forms creates the Pre-Delete trigger when the Delete Record Behavior property is set to Cascading. It deletes the records in the detail block's base table that correspond to the master record that is being deleted.
--
-- Begin default relation program section
--
BEGIN
--
-- Begin detail_block detail program section
--
DELETE FROM detail_block_base_table
WHERE foreign_key_column = :master_block.primary_key_item;
--
-- End detail_block detail program section
--
END;
--
-- End default relation program section
--