In Oracle Forms, what is the purpose of the WHEN-DATABASE-RECORD trigger and when does it fire?

Difficulty: Medium

Correct Answer: It fires when Oracle Forms fetches or brings a record from the database block into the form, allowing code to run for each database record

Explanation:


Introduction / Context:
Oracle Forms provides many triggers that allow developers to run custom code at specific points in the form life cycle. One of the less commonly understood triggers is WHEN-DATABASE-RECORD. This trigger is associated with database blocks and is related to records that come from the underlying database. The question aims to check whether you know when this trigger fires and what kind of logic you might place in it.


Given Data / Assumptions:

  • We are working with an Oracle Forms application that contains database blocks.
  • Records are queried from the database into the form for display and editing.
  • The WHEN-DATABASE-RECORD trigger is defined at the block level.
  • The developer wants to run code for each record that is fetched from the database.


Concept / Approach:
The WHEN-DATABASE-RECORD trigger is a block level trigger that fires when the form processes a record that already exists in the database. This typically happens when records are fetched from the database into the form. The trigger allows you to perform actions such as initializing derived items, setting visual attributes, or performing checks that apply to each record. It is different from WHEN-NEW-RECORD-INSTANCE, which fires when focus moves to a record, and different from WHEN-VALIDATE-RECORD, which fires when validation is performed before changes are saved. The key concept is that WHEN-DATABASE-RECORD is associated with records that come from the database and are being processed at runtime, not with form startup or unrelated events.


Step-by-Step Solution:
Step 1: Identify that the trigger name contains DATABASE-RECORD, suggesting a link to records stored in the database. Step 2: Recall that this trigger is defined at the block level for database blocks. Step 3: Understand that it fires when the form is dealing with records fetched from the database, letting you execute code for each record. Step 4: Review the options and find the one that states that it fires when Forms brings a record from the database into the form for processing. Step 5: Discard options that refer only to form startup, menu clicks, server shutdown, or design time behavior, as these do not match Forms trigger semantics.


Verification / Alternative check:
Oracle Forms documentation describes WHEN-DATABASE-RECORD as firing once for each record retrieved into the form from the database, before control is passed to the user. Developers use it to manipulate item values or perform derived calculations that depend on database data. The existence of other triggers such as WHEN-NEW-FORM-INSTANCE and WHEN-NEW-RECORD-INSTANCE clearly shows that initialization at form startup or navigation has separate triggers, confirming that WHEN-DATABASE-RECORD specifically relates to database records.


Why Other Options Are Wrong:
Option B is wrong because the trigger does not fire only once at form startup; that is the role of WHEN-NEW-FORM-INSTANCE or PRE-FORM. Option C is incorrect, since menu clicks unrelated to database access do not directly fire WHEN-DATABASE-RECORD. Option D is unrelated to Oracle Forms triggers, as shutting down the database server is an external event. Option E is incorrect because WHEN-DATABASE-RECORD is a runtime trigger, and developers rely on it to execute logic when records are fetched.


Common Pitfalls:
A typical confusion is mixing up different record related triggers, such as WHEN-NEW-RECORD-INSTANCE, WHEN-VALIDATE-RECORD, and WHEN-DATABASE-RECORD. Developers may also place heavy processing inside this trigger, which can slow down queries because it runs for each fetched record. It is important to understand the purpose of each trigger and use them appropriately so that the form remains responsive and maintainable.


Final Answer:
The correct description is that WHEN-DATABASE-RECORD fires when Oracle Forms fetches or brings a record from the database block into the form, allowing code to run for each database record processed at runtime.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion