53.95 PREPARE_URL Function


Oracle recommends using APEX_PAGE.GET_URL instead of PREPARE_URL for improved readability.

See GET_URL Function.

The PREPARE_URL function serves two purposes:

  1. To return an APEX navigation URL with the Session State Protection checksum argument (&cs=) if one is required. For security, the URL will not contain a checksum if the specified application is located in a different workspace.

  2. To return an APEX navigation URL with the session ID component replaced with zero (0) if the zero session ID feature is in use and other criteria are met.


The PREPARE_URL function returns the APEX navigation URL with &cs=<large hex value> appended. If you use this returned value (such as in JavaScript), you may need to escape the ampersand in the URL to conform with syntax rules of the particular context.


    p_url                    IN VARCHAR2,
    p_url_charset            IN VARCHAR2 default null,
    p_checksum_type          IN VARCHAR2 default null,
    p_triggering_element     IN VARCHAR2 default 'this'
    p_plain_url              IN BOOLEAN  default false 


Table 53-68 PREPARE_URL Parameters

Parameter Description
p_url An APEX navigation URL with all substitutions resolved.
p_url_charset The character set name (for example, UTF-8) to use when escaping special characters contained within argument values.

Null or any of the following values:

  • PUBLIC_BOOKMARK or 1 - Use this when generating links to be used by any user. For example, use this value when generating an email which includes links to an application.

  • PRIVATE_BOOKMARK or 2 - Use this when generating a link to be used outside of the current session. This option can only be used by the same currently authenticated user.

  • SESSION or 3 - Use this when generating links to an application. This option can only be used within the current session.

p_triggering_element A jQuery selector (for example, #my_button , where my_button is the static ID for a button element), to identify which element to use to trigger the dialog. This is required for Modal Dialog support.
p_plain_url If the page you are calling APEX_UTIL.PREPARE_URL from is a modal dialog, specify p_plain_url to omit the unnecessary JavaScript code in the generated link. By default, if this function is called from a modal dialog, JavaScript code to close the modal dialog is included in the generated URL.

Example 1

The following example shows how to use the PREPARE_URL function to return a URL with a valid 'SESSION' level checksum argument. This URL sets the value of P1_ITEM page item to xyz.

    l_url varchar2(2000);
    l_app number := v('APP_ID');
    l_session number := v('APP_SESSION');
        p_url => 'f?p=' || l_app || ':1:'||l_session||'::NO::P1_ITEM:xyz',
        p_checksum_type => 'SESSION');

Example 2

The following example shows how to use the PREPARE_URL function to return a URL with a zero session ID. In a PL/SQL Dynamic Content region that generates f?p URLs (anchors), call PREPARE_URL to ensure that the session ID is set to zero when the zero session ID feature is in use, when the user is a public user (not authenticated), and when the target page is a public page in the current application:

htp.p(APEX_UTIL.PREPARE_URL(p_url => 'f?p=' || :APP_ID || ':10:'|| :APP_SESSION

When using PREPARE_URL for this purpose, the p_url_charset and p_checksum_type arguments can be omitted. However, it is permissible to use them when both the Session State Protection and Zero Session ID features are applicable.

See Also:

About Enabling Support for Bookmarks in Oracle APEX App Builder User’s Guide.