In Oracle APEX, users interact with session state as they enter data, navigate between pages, or submit forms. Over time, session values can accumulate and affect how pages behave—especially during testing or repeated use. Implementing a "Clear Session" button is a simple and powerful way to reset the application to a clean state by clearing all session variables. This is especially useful for developers, testers, or end users who need to return to a default state without manually clearing individual items. This blog explains how to build and use a "Clear Session" button in Oracle APEX.
How to Implement a "Clear Session" Button in Oracle APEX
-
Add a Button to Your Page
-
Open your target page in Page Designer
-
Under the Regions section, click + and add a Button
-
Set the button label to
Clear Session
-
Give it a static ID like
BTN_CLEAR_SESSION
if you need to reference it in JavaScript
-
-
Create a Dynamic Action for the Button
-
Under Dynamic Actions, click Create
-
Event: Click
-
Selection Type: Button
-
Button: Select your
Clear Session
button -
Add a True Action:
-
Action: Execute PL/SQL Code
-
PL/SQL Code:
apex_util.clear_page_cache(:APP_ID);
-
This clears the session state for the entire application
-
-
-
Add a Page Redirect After Clearing
-
Add another True Action:
-
Action: Redirect to Page in This Application
-
Set the target to the page you want the user to return to, usually the home or login page
-
-
Optional: Use JavaScript to Show Feedback
You can add a spinner or notification message to indicate that the session is being cleared, depending on the user experience you want.
The Clear Session button resets the values of FName and LName by clearing the session state.
Implementation Steps
Set the Button Action to Defined by Dynamic Action.
Create a Dynamic Action with the following attributes:
Event: Click
Action: Execute PL/SQL Code
PL/SQL Code:
apex_util.clear_page_cache(:APP_PAGE_ID);
Affected Elements:
Selection Type: Items
Items: P1_FNAME, P1_LNAME
This ensures that the values in the text fields are cleared when the button is clicked.
Best Practices for a Clear Session Button
-
Use it in admin or developer-facing areas to avoid disrupting normal users unintentionally
-
Clearly label the button and optionally confirm before executing
-
Combine with a spinner or message so the user knows something is happening
-
Redirect users to a safe, known page after clearing session state
-
Only include this button where needed—not on every page
Avoid clearing session state while users are in the middle of data entry or transactions
Oracle APEX Documentation Links
Conclusion
A "Clear Session" button in Oracle APEX is a simple but effective tool for maintaining clean session state during development, testing, or controlled user flows. It resets the application without requiring manual item-by-item clearing and ensures predictable page behavior. By combining PL/SQL with dynamic actions and smart UX design, you can implement a safe and user-friendly reset mechanism in just a few steps.