Search This Blog

Tuesday, July 8, 2025

How do I Apply Format Masks to Items in Oracle APEX

 

Introduction
Applying format masks to items in Oracle APEX allows you to control how data such as dates, numbers, and currencies are displayed to users. Format masks improve readability, ensure consistency across your application, and help users understand the expected input or output. Whether you're working with a date picker, a numeric field, or a display-only item, using the right format mask enhances both usability and presentation.

 Applying format masks to items in Oracle APEX is an essential step in controlling how data is displayed to users. Format masks do not change the stored data; they simply change how that data appears on screen. This is especially useful for dates, times, numbers, and currency values. Oracle APEX provides multiple places where you can apply format masks depending on the item type and how the data is presented.

To apply a format mask in Oracle APEX, follow these detailed steps:

  1. Open Page Designer
    In APEX App Builder, go to your application and open the page containing the item you want to format.

  2. Select the Item
    Click on the item (e.g., a date picker, text field, number field, or display-only item) in the Rendering tree or Layout view.

  3. Find the Format Mask Property
    In the Property Editor, scroll down to the Appearance section. There you’ll find a field labeled Format Mask.

  4. Enter the Format Mask
    Enter the appropriate format mask string based on the item’s data type. Some common examples:

    • Date Format Masks

      • DD-MON-YYYY → 05-JUL-2025

      • MM/DD/YYYY → 07/05/2025

      • YYYY-MM-DD HH24:MI:SS → 2025-07-05 13:45:00
        These are based on Oracle’s TO_CHAR format models.

    • Number Format Masks

      • 999,999.99 → 12,345.67

      • 000000 → 000123

      • FM9990.00 → removes leading/trailing spaces and shows two decimals.

    • Currency Format Masks

      • L999G999D00 → $1,234.56 (uses local currency symbol)

      • FML999G999D00 → no space before symbol, tight formatting

  5. Display-Only Items
    If your item is set as Display Only, you can still apply a format mask. Just make sure Escape Special Characters is set to No if your format includes currency symbols or special characters.

  6. Interactive Reports or Grids
    If you're working with an Interactive Report, Classic Report, or Interactive Grid, you can apply format masks to columns as well:

    • Open the Region (e.g., your report).

    • Locate the column under Columns.

    • In the Column Attributes, scroll to the Appearance section.

    • Enter your desired format mask under Number/Date Format.

  7. Dynamic Formatting via PL/SQL or JavaScript (Optional)
    In some cases, you may want to control formatting using PL/SQL or JavaScript. For example, you could format a date using a PL/SQL process:

    :P1_FORMATTED_DATE := TO_CHAR(:P1_DATE, 'DD/MM/YYYY');
    

    Or use JavaScript with the Intl.NumberFormat or toLocaleString() functions to handle locale-based formats on the client side.

  8. Preview and Test
    Run the application, enter or display values in the formatted item, and verify that they appear exactly as intended.

By using format masks in Oracle APEX, you can ensure that users always see data in a clear, readable, and standardized format. Whether you're localizing for global users or aligning to business rules, format masks give you full control over presentation without modifying your data structure.

 

Oracle APEX applies globalization settings automatically when rendering each page. These settings can affect how numbers, dates, and other formatted data appear based on the user’s session language and territory. To ensure consistency in data presentation, format masks can be applied to items such as text fields, number fields, and date pickers.

 

What Are Format Masks?

A format mask is a pattern that controls how data is displayed or entered in an item. It ensures that values are formatted correctly based on locale settings and prevents inconsistent data entry. Format masks are particularly useful for:

  • Dates: Displaying dates in a consistent format (e.g., DD-MON-YYYY).

  • Numbers: Controlling decimal and thousand separators (999G999D99).

  • Currency: Formatting monetary values ($999,999.99).

  • Text: Converting input to uppercase (UPPER).

 

How to Apply a Format Mask to an Item

  1. Open the Page Designer

    • Navigate to App Builder.

    • Select the application and page where the item is located.

  2. Select the Item

    • In Page Designer, find the item that needs a format mask.

    • Click on the item to open its properties.

  3. Apply a Format Mask

    • In the Property Editor, find the Format Mask property.

    • Enter the appropriate format mask based on the data type.

  4. Save and Run the Page

    • Click Save and Run to test the format mask.

 

Common Format Masks in Oracle APEX

Date Format Masks

Format Mask

Description

Example Output

DD-MON-YYYY

Day, abbreviated month, and year

15-MAR-2025

YYYY-MM-DD

ISO standard format

2025-03-15

MM/DD/YYYY

U.S. style date format

03/15/2025

DD/MM/YYYY HH24:MI

Date with 24-hour time

15/03/2025 14:30

Number Format Masks

Format Mask

Description

Example Output

999G999D99

Standard number format

1,234.56

0000

Leading zeros

0045

99.99

Fixed decimal places

12.30

99999PR

Negative values in parentheses

(1000)

Currency Format Masks

Format Mask

Description

Example Output

$999,999.99

U.S. currency format

$1,234.56

L999G999D99

Uses session locale

€1.234,56 (for German locale)

99999.99 C

Currency symbol at the end

1234.56 USD

Text Formatting

Format Mask

Description

Example Output

UPPER

Converts input to uppercase

HELLO

LOWER

Converts input to lowercase

hello

INITCAP

Capitalizes first letter of each word

Hello World

 

Overriding Default Globalization Behavior

If Oracle APEX is applying unwanted automatic formatting based on globalization settings, use explicit format masks for date and number items.

Example: Force a Specific Date Format

If a session is set to a European locale (DD.MM.YYYY), but you need MM/DD/YYYY, apply the format mask explicitly:

  1. Open Page Designer.

  2. Select the date item.

  3. Set the Format Mask to MM/DD/YYYY.

  4. Save and run the application.

This ensures that dates always appear in the expected format, regardless of session settings.

 

Best Practices for Using Format Masks

  • Use consistent formats across the application to avoid confusion.

  • Match format masks with database column formats to prevent conversion errors.

  • Consider user locale settings when defining format masks for currency and numbers.

  • Test different APEX session languages and territories to ensure correct formatting.

Applying format masks correctly in Oracle APEX enhances user experience, maintains data integrity, and ensures that applications display information in a predictable and professional manner.

Conclusion
Format masks in Oracle APEX offer a simple yet powerful way to tailor the display of item values without altering the underlying data. By applying the appropriate format masks to items, you ensure your application communicates information clearly and aligns with regional or business-specific display standards. It's a key part of creating polished, professional, and user-friendly APEX applications.

No comments:

Post a Comment

How Do I Make a Faceted Search Map Page in Oracle APEX

Combining faceted search with a map region in Oracle APEX enables users to filter data visually and spatially at the same time. This design ...