Oracle Forms has a data validation model that makes it easy to validate data in records that have been entered or updated by the operator. Many of the most common validation requirements can be handled by setting the following item-level properties:
To add application-specific validation, write a When-Validate-Item or When-Validate-Record trigger for the item or block. When-Validate-Item fires when Oracle Forms during the Leave the Item event, just after Oracle Forms performs its own validation checks. When-Validate-Record fires during the Leave the Record event, when Oracle Forms checks to ensure that all of the items in the current record are marked valid before navigating to the target record.
A common validation requirement is to ensure that items which correspond to primary key columns in the database have unique values. The Oracle Database Server enforces NOT NULL and UNIQUE Constraints that can accomplish this for you at the kernel level. However, it is usually desirable to give operators immediate feedback on such errors during data entry, rather than waiting for an ORACLE error to be displayed at commit time.
To check that a primary key value is unique immediately after it is entered by the operator, create a When-Validate-Item trigger that issues a SELECT statement to check if the value already exists in the block's datasource.
Note: You can also enforce unique primary keys by setting the Enforce Primary Key block and Primary Key item properties. However, these properties are set, Oracle Forms does not check for duplicate values until commit time, when it processes each UPDATE or INSERT for the block. Setting these properties provides no advantage over using comparable database Constraints, because in both cases, duplicate primary key values are not flagged until commit time.