Search This Blog

Tuesday, June 24, 2025

How Do I Add Validations and Error Message

Validations and Error Messages in Oracle APEX

Validations in Oracle APEX ensure that user inputs meet specific criteria before processing the data. If a validation fails, an error message is displayed to the user, preventing incorrect or incomplete data from being saved.

You can use validations to check data a user enters before processing. Once you create a validation and the associated error message, you can associate it with a specific item. You can choose to have validation error messages display inline (that is, on the page where the validation is performed) or on a separate error page.

Creating an inline error message involves these steps:

  • Step 1 - Create a validation and specify error message text. 

  • Step 2 - Associate the validation with a specific item.


This tutorial covers the different types of validations available in APEX, how to create them, and how to customize error messages.


Types of Validations in APEX

There are several types of validations in APEX, each suited for different scenarios.

1. Item-Level Validations

These validations apply to individual page items, such as text fields, number fields, or select lists.

Examples include:

  • Checking if a field is empty

  • Validating email format

  • Ensuring a number is within a specific range

2. Row-Level Validations

These validations apply to entire rows when using an Interactive Grid or Forms that insert or update database records.

Examples include:

  • Ensuring a record is unique

  • Checking if a value already exists in the database

3. Processing-Level Validations

These validations apply when submitting data through a process, such as an INSERT or UPDATE statement.

Examples include:

  • Ensuring business rules are followed

  • Validating multiple fields together


Creating Validations in APEX

Step 1: Adding a Required Field Validation

  1. Open Page Designer in APEX.

  2. Select the page item (e.g., P1_EMAIL).

  3. Under the Validation section, click Create.

  4. Choose Not Null as the validation type.

  5. Enter a custom error message, such as:

"Email address cannot be empty. Please enter an email."

  1. Click OK, then Save and Run the Page.

If the field is left empty and the user tries to submit the form, the error message will be displayed.


Step 2: Validating an Email Format

  1. Create a new validation on the P1_EMAIL item.

  2. Select Regular Expression as the validation type.

  3. Use the following regex pattern to validate email format:

^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$

  1. Enter an error message such as:

"Invalid email format. Please enter a valid email address."

  1. Click Save and Run the Page, then test by entering an incorrect email format.


Step 3: Checking If a Value Already Exists in the Database

To prevent duplicate records, create a validation that checks if a value already exists in the database.

  1. Open Page Designer and select the item, such as P1_USERNAME.

  2. Under the Validation section, click Create.

  3. Select PL/SQL Function Returning Boolean.

  4. Enter the following PL/SQL code:

DECLARE

    v_count NUMBER;

BEGIN

    SELECT COUNT(*) INTO v_count 

    FROM USERS 

    WHERE USERNAME = :P1_USERNAME;


    RETURN v_count = 0;

END;

  1. Enter an error message, such as:

"This username is already taken. Please choose another."

  1. Click Save and Run the Page, then test by entering a duplicate username.


Customizing Error Messages

Step 1: Using a Friendly Error Display

  1. Open Shared ComponentsMessages.

  2. Click Create and enter an error code, such as ERR_DUPLICATE_USERNAME.

  3. Enter a custom error message, such as:

"This username is already registered. Try another name."

  1. Modify your validation to return this error code instead of a static message.


Step 2: Using JavaScript to Display Error Messages

To show a custom error message dynamically using JavaScript, follow these steps:

  1. Add a Dynamic Action triggered on button click.

  2. Set the action to Execute JavaScript Code.

  3. Enter the following code to display an alert if a field is empty:

if (!$('#P1_USERNAME').val()) {

    apex.message.alert('Please enter a username before submitting.');

}

  1. Click Save and Run the Page, then test by clicking the button without entering a username.


Best Practices for Using Validations in APEX

  • Use Not Null validations for required fields to ensure they are always filled.

  • Apply Regular Expressions for format validation, such as emails or phone numbers.

  • Use PL/SQL Validations for database checks, such as ensuring uniqueness.

  • Display friendly error messages to guide users instead of generic error codes.

  • Use JavaScript for real-time feedback before form submission.


Validations in Oracle APEX help enforce data integrity and improve user experience by ensuring inputs meet specific requirements. By combining item-level, row-level, and process-level validations, along with custom error messages, you can create a more reliable and user-friendly application.


A screenshot of a computer

AI-generated content may be incorrect.


Navigation Bar and Menu

 The basics:

Understanding Navigation in Oracle APEX

Oracle APEX provides three standard navigation components at the application level:

  1. Navigation Bar

  2. Navigation Menu

  3. Breadcrumbs

Each serves a specific purpose in helping users navigate an application efficiently.


1. Navigation Bar

The Navigation Bar is a persistent UI element displayed at the top of every page in an APEX application. It is automatically included when an application is created.

Key Features

Always visible at the top of the page.
Typically used for global actions, such as:

  • User authentication links (Login, Logout, Profile)

  • Help or Documentation links

  • Quick links to key pages

Customization

Developers can modify or extend the Navigation Bar by:

  • Changing icons, text, and list entries.

  • Controlling visibility based on user roles or conditions.

  • Defining whether to display as text links or icons.


2. Navigation Menu

The Navigation Menu serves as the primary application menu, allowing users to access different pages. It is included by default when an application is created.

Display Options

The Navigation Menu can be positioned:

  • On the Side (Left or Right Panel) – Often used for dashboard-style layouts.

  • At the Top (Horizontal Menu) – Suitable for tab-based navigation.

Types of Navigation Menus

APEX supports two primary menu structures:

  1. Lists – A simple, hierarchical menu structure.

  2. Tree Lists – A collapsible, hierarchical structure ideal for complex applications.

Customization

Developers can modify the Navigation Menu by:

  • Defining menu items statically (manually entered) or dynamically (fetched from a table or query).

  • Controlling visibility based on user authentication or authorization levels.

  • Adding icons, separators, and hierarchical submenus.


3. Breadcrumbs

Breadcrumbs provide contextual navigation, helping users track their current location within an application. Unlike the Navigation Bar and Menu, breadcrumbs are not included by default but can be added as the application evolves.

Key Features

  • Displays a hierarchical trail of visited pages.

  • Helps users navigate back to previous levels without relying on the browser’s back button.

  • Typically follows a Home > Section > Page format.

Customization

Developers can:

  • Define breadcrumbs manually or generate them dynamically.

  • Customize their appearance using styles and templates.

  • Set custom URLs for specific breadcrumb links.


Best Practices for Navigation in Oracle APEX

  •  Keep Navigation Simple – Avoid cluttered menus and only include essential links.

  •  Use Role-Based Access – Restrict certain navigation items based on user permissions.

  •  Ensure Consistency – Maintain a uniform navigation experience across pages.

  • Leverage Dynamic Menus – Use SQL queries to generate menus dynamically based on user roles or permissions.


Oracle APEX provides flexible and customizable Navigation Bar, Navigation Menu, and Breadcrumbs to enhance user experience. Developers can modify these elements to suit application requirements, ensuring intuitive, efficient navigation for users.

Both the Navigation Bar and Menu are visual representation of lists or tree lists. The developer has the ability to modify these lists and to generate them in static or dynamic manners.


A screenshot of a computer

AI-generated content may be incorrect.


UI Defaults

 In Oracle APEX, User Interface (UI) Defaults are a set of metadata-driven, table- and column-scoped attributes that APEX consults when it g...