Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/TechFernandesLTDA/apex-mcp/llms.txt

Use this file to discover all available pages before exploring further.

Server-side validations in Oracle APEX run on page submit, before any page processing takes place. When a validation fails, APEX stops execution, displays the error message inline next to the failing field (and in the notification area), and does not execute any page processes. This makes validations the correct place to enforce data integrity rules — not inside the DML process itself. apex-mcp provides two tools in this space: apex_add_item_validation to attach rules to individual page items, and apex_add_item_computation to derive or pre-populate item values at specific points in the page lifecycle.

apex_add_item_validation

Add a validation rule to a page item. Validations created by this tool run at INLINE_WITH_FIELD_AND_NOTIFICATION display location, meaning errors appear both beside the field and in the page-level notification banner.
apex_add_item_validation(
    page_id=10,
    item_name="P10_FIRST_NAME",
    validation_name="First Name Required",
    validation_type="not_null",
    error_message="First Name is required.",
    sequence=10,
)

Parameters

page_id
int
required
Page ID containing the item to validate.
item_name
string
required
The item to validate, e.g. "P10_EMAIL". Automatically prefixed with P{page_id}_ if the prefix is missing.
validation_name
string
required
Display name for this validation rule, shown in the App Builder and in error messages. Use a descriptive name like "Email Required" or "Salary Range Check".
validation_type
string
default:"not_null"
Type of validation. Accepted values and their APEX internal mapping:
Friendly nameAPEX typeDescription
not_nullITEM_NOT_NULLItem must not be empty. No validation_expression needed.
max_lengthMAX_LENGTHItem value must not exceed N characters. Set N in validation_expression.
min_lengthMIN_LENGTHItem must have at least N characters. Set N in validation_expression.
regexREGULAR_EXPRESSIONItem must match the regex pattern in validation_expression.
plsql_expressionPLSQL_EXPRESSIONA PL/SQL boolean expression (referencing items via :P{n}_ITEM bind vars) that must evaluate to TRUE.
plsql_functionPLSQL_FUNCTION_RETURNING_ERROR_TEXTA PL/SQL function body that returns NULL when valid or an error message string when invalid.
item_not_null_or_zeroITEM_NOT_NULL_OR_ZEROItem must not be null or zero. Useful for numeric required fields.
validation_expression
string
The rule expression whose meaning depends on validation_type:
validation_typeWhat to put here
not_null(not used — item name is implicit)
max_lengthMaximum number of characters as a string, e.g. "100"
min_lengthMinimum number of characters as a string, e.g. "8"
regexRegular expression pattern, e.g. "^[0-9]+$"
plsql_expressionBoolean PL/SQL expression, e.g. ":P10_AGE > 0 AND :P10_AGE < 120"
plsql_functionFull PL/SQL anonymous function body returning NULL or an error string
item_not_null_or_zero(not used — item name is implicit)
error_message
string
Message displayed to the user when the validation fails. Auto-generated from the item name and type if omitted — but providing an explicit, user-friendly message is strongly recommended.
sequence
int
default:"10"
Execution order. Validations run in ascending sequence order. Lower numbers run first.
condition_item
string
Optional item name: only run this validation when the specified item is not null. Useful for conditional fields that are only required in certain states (e.g. only validate P10_MANAGER_ID when P10_DEPT_TYPE = 'MANAGED').

Return Value

{
  "status": "ok",
  "validation_id": 88888,
  "validation_name": "Email Format",
  "validation_type": "REGULAR_EXPRESSION",
  "item_name": "P10_EMAIL",
  "page_id": 10,
  "error_message": "Please enter a valid email address.",
  "message": "Validation 'Email Format' added to item 'P10_EMAIL' on page 10."
}

apex_add_item_computation

Add a computation to derive or pre-populate a page item’s value at a specified point in the page lifecycle. Computations fire automatically — no user interaction is required. Common uses: pre-populate a form field from the database when the page loads, copy the current user’s name from a session variable, or derive a calculated value after submit.
apex_add_item_computation(
    page_id=10,
    item_name="P10_STATUS",
    computation_type="static_value",
    computation_expression="ACTIVE",
    computation_point="BEFORE_HEADER",
    sequence=10,
)

Parameters

page_id
int
required
Page ID.
item_name
string
required
The item whose value will be set, e.g. "P10_FULL_NAME". Automatically prefixed with P{page_id}_ if the prefix is missing.
computation_type
string
default:"static_value"
How the value is derived. Accepted values and their APEX internal mapping:
Friendly nameAPEX typeDescription
static_valueSTATIC_ASSIGNMENTA literal fixed string
plsql_expressionPLSQL_EXPRESSIONA PL/SQL expression evaluated at runtime (e.g. ":APP_USER")
plsql_functionPLSQL_FUNCTION_BODYA PL/SQL function body that returns the value
queryQUERYA SQL SELECT returning a single value
item_valueITEM_VALUECopy the value from another item (name in computation_expression)
sequenceSEQUENCEGet the next value from a DB sequence (sequence name in computation_expression)
computation_expression
string
The value, expression, SQL, or source item name — interpreted according to computation_type:
computation_typeWhat to put here
static_valueThe literal string to assign, e.g. "ACTIVE"
plsql_expressionPL/SQL expression, e.g. `“:APP_USER’@company.com’“`
plsql_functionFull PL/SQL function body returning the value
querySingle-row SELECT statement returning one column
item_valueName of the source item, e.g. "APP_USER_ROLE"
sequenceDB sequence name, e.g. "EMP_SEQ"
computation_point
string
default:"BEFORE_HEADER"
When in the page lifecycle the computation runs:
ValueWhen it fires
BEFORE_HEADERBefore the page renders — use for initialization and pre-populating edit forms
AFTER_SUBMITAfter the user submits the page — use for post-processing derived fields
BEFORE_BOX_BODYBefore the page body region renders
sequence
int
default:"10"
Execution order when multiple computations exist for the same item or page.
condition_item
string
Optional item name: only execute this computation when the specified item is not null. This is the standard way to differentiate between “new record” (condition item is null, i.e. no PK yet) and “edit record” (condition item is not null) scenarios.

Return Value

{
  "status": "ok",
  "computation_id": 99999,
  "item_name": "P10_FULL_NAME",
  "computation_type": "QUERY",
  "computation_point": "BEFORE_HEADER",
  "page_id": 10,
  "message": "Computation added to item 'P10_FULL_NAME' on page 10 (point: BEFORE_HEADER)."
}

Practical Examples

Required fields with format validation

Add NOT_NULL and email-format validations to a contact form on page 10:
# Required: email cannot be blank
apex_add_item_validation(
    page_id=10,
    item_name="P10_EMAIL",
    validation_name="Email Required",
    validation_type="not_null",
    error_message="Email address is required.",
    sequence=10,
)

# Format: email must match RFC-5321-style pattern
apex_add_item_validation(
    page_id=10,
    item_name="P10_EMAIL",
    validation_name="Email Format",
    validation_type="regex",
    validation_expression=r"^[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}$",
    error_message="Please enter a valid email address (e.g. user@example.com).",
    sequence=20,
)

SQL computation to set a derived display field

Pre-populate P10_FULL_NAME from the database when opening an existing employee record:
apex_add_item_computation(
    page_id=10,
    item_name="P10_FULL_NAME",
    computation_type="query",
    computation_expression="""
SELECT first_name || ' ' || last_name
  FROM employees
 WHERE emp_id = :P10_EMP_ID
""",
    computation_point="BEFORE_HEADER",
    sequence=10,
    condition_item="P10_EMP_ID",  # only when editing (EMP_ID is populated)
)

Cross-field validation with PL/SQL expression

Ensure the end date is after the start date:
apex_add_item_validation(
    page_id=20,
    item_name="P20_END_DATE",
    validation_name="End Date After Start",
    validation_type="plsql_expression",
    validation_expression=":P20_END_DATE > :P20_START_DATE",
    error_message="End Date must be after Start Date.",
    sequence=10,
    condition_item="P20_END_DATE",  # only validate when end date is provided
)

Uniqueness check with PL/SQL function

Verify a username is not already in use (excluding the current record):
apex_add_item_validation(
    page_id=10,
    item_name="P10_USERNAME",
    validation_name="Username Unique",
    validation_type="plsql_function",
    validation_expression="""
declare
  v_count number;
begin
  select count(*) into v_count
    from app_users
   where upper(username) = upper(:P10_USERNAME)
     and user_id != nvl(to_number(:P10_USER_ID), -1);

  if v_count > 0 then
    return 'This username is already in use. Please choose a different one.';
  end if;
  return null;
end;
""",
    error_message="Username already exists.",
    sequence=30,
)

Notes on Validation Types

not_null vs is_required on the item — Setting is_required=True on apex_add_item adds a visual required indicator (*) and applies the required field template, but does not add a server-side validation. You must call apex_add_item_validation with validation_type="not_null" separately if you want enforcement on submit.
plsql_function returns the error message — Unlike plsql_expression (which must return TRUE/FALSE), the plsql_function type returns NULL to signal success and a non-null string to signal failure. The returned string becomes the error message shown to the user, so you can generate dynamic, data-driven error messages.
Bind variables in PL/SQL validations — Reference page items using :P{page_id}_ITEM_NAME syntax inside plsql_expression and plsql_function bodies. Application items are referenced as :APP_ITEM_NAME. These are Oracle bind variables resolved by APEX at execution time.
Validations run on every page submit unless you add a condition_item. If you have a page with multiple submit buttons (Save, Delete), ensure your validations have appropriate conditions so a Delete action is not blocked by a missing required field that is irrelevant for deletion.

Build docs developers (and LLMs) love