PK
8Aoa, mimetypeapplication/epub+zipPK 8A iTunesMetadata.plistE
You can use APEX_PLSQL_JOB package to run PL/SQL code in the background of your application. This is an effective approach for managing long running operations that do not need to complete for a user to continue working with your application.
Topics in this section include:
Call this function to determine whether or not the database is currently in a mode that supports submitting jobs to the APEX_PLSQL_JOB package.
Syntax
APEX_PLSQL_JOB.JOBS_ARE_ENABLED RETURN BOOLEAN;
Parameters
None.
Example
The following example shows how to use the JOBS_ARE_ENABLED function. In the example, if the function returns TRUE the message 'Jobs are enabled on this database instance' is displayed, otherwise the message 'Jobs are not enabled on this database instance' is displayed.
BEGIN
IF APEX_PLSQL_JOB.JOBS_ARE_ENABLED THEN
HTP.P('Jobs are enabled on this database instance.');
ELSE
HTP.P('Jobs are not enabled on this database instance.');
END IF;
END;
Call this procedure to clean up submitted jobs. Submitted jobs stay in the APEX_PLSQL_JOBS view until either Oracle Application Express cleans out those records, or you call PURGE_PROCESS to manually remove them.
Syntax
APEX_PLSQL_JOB.PURGE_PROCESS (
p_job IN NUMBER);
Parameters
Table 10-1 describes the parameters available in the PURGE_PROCESS procedure.
Table 10-1 PURGE_PROCESS Parameters
| Parameter | Description |
|---|---|
|
|
The job number that identifies the submitted job you wish to purge. |
Example
The following example shows how to use the PURGE_PROCESS procedure to purge the submitted job identified by a job number of 161. You could also choose to purge all or some of the current submitted jobs by referencing the APEX_PLSQL_JOBS view.
BEGIN
APEX_PLSQL_JOB.PURGE_PROCESS(
p_job => 161);
END;
Use this procedure to submit background PL/SQL. This procedure returns a unique job number. Because you can use this job number as a reference point for other procedures and functions in this package, it may be useful to store it in your own schema.
Syntax
APEX_PLSQL_JOB.SUBMIT_PROCESS (
p_sql IN VARCHAR2,
p_when IN DATE DEFAULT SYSDATE,
p_status IN VARCHAR2 DEFAULT 'PENDING')
RETURN NUMBER;
Parameters
Table 10-2 describes the parameters available in the SUBMIT_PROCESS function.
Table 10-2 SUBMIT_PROCESS Parameters
| Parameter | Description |
|---|---|
|
|
The process you wish to run in your job. This can be any valid anonymous block, for example: 'BEGIN <your code> END;' or 'DECLARE <your declaration> BEGIN <your code> END;' |
|
p_when |
When you want to run it. The default is SYSDATE which means the job will run as soon as possible. You can also set the job to run in the future, for example:
|
|
p_status |
Plain text status information for this job. |
Example
The following example shows how to use the SUBMIT_PROCESS function to submit a background process that will start as soon as possible.
DECLARE
l_sql VARCHAR2(4000);
l_job NUMBER;
BEGIN
l_sql := 'BEGIN MY_PACKAGE.MY_PROCESS; END;';
l_job := APEX_PLSQL_JOB.SUBMIT_PROCESS(
p_sql => l_sql,
p_status => 'Background process submitted');
--store l_job for later reference
END;
Use this function to determine how much time has elapsed since the job was submitted.
Syntax
APEX_PLSQL_JOB.TIME_ELAPSED(
p_job IN NUMBER)
RETURN NUMBER;
Parameters
Table 10-3 describes the parameters available in the TIME_ELAPSED function.
Table 10-3 TIME_ELAPSED Parameters
| Parameter | Description |
|---|---|
|
|
The job ID for the job you wish to see how long since it was submitted. |
Example
The following example shows how to use the TIME_ELAPSED function to get the time elapsed for the submitted job identified by the job number 161.
DECLARE
l_time NUMBER;
BEGIN
l_time := APEX_PLSQL_JOB.TIME_ELAPSED(p_job => 161);
END;
Call this procedure to update the status of the currently running job. This procedure is most effective when called from the submitted PL/SQL.
Syntax
APEX_PLSQL_JOB.UPDATE_JOB_STATUS (
p_job IN NUMBER,
p_status IN VARCHAR2);
Parameters
Table 10-4 describes the parameters available in the UPDATE_JOB_STATUS procedure.
Table 10-4 UPDATE_JOB_STATUS Parameters
| Parameter | Description |
|---|---|
|
|
Passed the reserved word JOB. When this code is executed it will have visibility to the job number via the reserved word JOB. |
|
p_status |
Plain text that you want associated with
|
Example
The following example shows how to use the UPDATE_JOB_STATUS procedure. In this example, note that:
Lines 002 to 010 run a loop that inserts 100 records into the emp table.
APP_JOB is referenced as a bind variable inside the VALUES clause of the INSERT, and specified as the p_job parameter value in the call to UPDATE_JOB_STATUS.
APP_JOB represents the job number which will be assigned to this process as it is submitted to APEX_PLSQL_JOB. By specifying this reserved item inside your process code, it will be replaced for you at execution time with the actual job number.
Note that this example calls to UPDATE_JOB_STATUS every ten records, inside the block of code. Normally, Oracle transaction rules dictate updates made inside code blocks will not be seen until the entire transaction is committed. The APEX_PLSQL_JOB.UPDATE_JOB_STATUS procedure, however, has been implemented in such a way that the update will happen regardless of whether or not the job succeeds or fails. This last point is important for two reasons:
Even if your status shows "100 rows inserted", it does not mean the entire operation was successful. If an error occurred at the time the block of code tried to commit, the user_status column of APEX_PLSQL_JOBS would not be affected because status updates are committed separately.
Updates are performed autonomously. You can view the job status before the job has completed. This gives you the ability to display status text about ongoing operations in the background as they are happening.
BEGIN
FOR i IN 1 .. 100 LOOP
INSERT INTO emp(a,b) VALUES (:APP_JOB,i);
IF MOD(i,10) = 0 THEN
APEX_PLSQL_JOB.UPDATE_JOB_STATUS(
P_JOB => :APP_JOB,
P_STATUS => i || ' rows inserted');
END IF;
APEX_UTIL.PAUSE(2);
END LOOP;
END;
The APEX_UTIL package provides utilities you can use when programming in the Oracle Application Express environment. You can use the APEX_UTIL package to get and set session state, get files, check authorizations for users, reset different states for users, get and purge cache information and also to get and set preferences for users.
Topics in this section include:
This function returns the date and time a specified application page was cached either for the user issuing the call, or for all users if the page was not set to be cached by user.
Syntax
APEX_UTIL.CACHE_GET_DATE_OF_PAGE_CACHE (
p_application IN NUMBER,
p_page IN NUMBER)
RETURN DATE;
Parameters
Table 1-1 describes the parameters available in the CACHE_GET_DATE_OF_PAGE_CACHE procedure.
Table 1-1 CACHE_GET_DATE_OF_PAGE_CACHE Parameters
| Parameter | Description |
|---|---|
|
|
The identification number (ID) of the application. |
|
|
The page number (ID). |
Example
The following example demonstrates how to use the CACHE_GET_DATE_OF_PAGE_CACHE function to retrieve the cache date and time for page 9 of the currently executing application. If page 9 has been cached, the cache date and time is output using the HTP package. The page could have been cached either by the user issuing the call, or for all users if the page was not to be cached by the user.
DECLARE
l_cache_date DATE DEFAULT NULL;
BEGIN
l_cache_date := APEX_UTIL.CACHE_GET_DATE_OF_PAGE_CACHE(
p_application => :APP_ID,
p_page => 9);
IF l_cache_date IS NOT NULL THEN
HTP.P('Cached on ' || TO_CHAR(l_cache_date, 'DD-MON-YY HH24:MI:SS'));
END IF;
END;
This function returns the date and time a specified region was cached either for the user issuing the call, or for all users if the page was not set to be cached by user.
Syntax
APEX_UTIL.CACHE_GET_DATE_OF_REGION_CACHE (
p_application IN NUMBER,
p_page IN NUMBER,
p_region_name IN VARCHAR2)
RETURN DATE;
Parameters
Table 1-2 describes the parameters available in the CACHE_GET_DATE_OF_REGION_CACHE function.
Table 1-2 CACHE_GET_DATE_OF_REGION_CACHE Parameters
| Parameter | Description |
|---|---|
|
|
The identification number (ID) of the application |
|
|
The page number (ID) |
|
|
The region name |
Example
The following example demonstrates how to use the CACHE_GET_DATE_OF_REGION_CACHE function to retrieve the cache date and time for the region named Cached Region on page 13 of the currently executing application. If the region has been cached, the cache date and time is output using the HTP package. The region could have been cached either by the user issuing the call, or for all users if the page was not to be cached by user.
DECLARE
l_cache_date DATE DEFAULT NULL;
BEGIN
l_cache_date := APEX_UTIL.CACHE_GET_DATE_OF_REGION_CACHE(
p_application => :APP_ID,
p_page => 13,
p_region_name => 'Cached Region');
IF l_cache_date IS NOT NULL THEN
HTP.P('Cached on ' || TO_CHAR(l_cache_date, 'DD-MON-YY HH24:MI:SS'));
END IF;
END;
This procedure purges all cached pages and regions for a given application.
Syntax
APEX_UTIL.CACHE_PURGE_BY_APPLICATION (
p_application IN NUMBER);
Parameters
Table 1-3 describes the parameters available in the CACHE_PURGE_BY_APPLICATION procedure.
Table 1-3 CACHE_PURGE_BY_APPLICATION Parameters
| Parameter | Description |
|---|---|
|
|
The identification number (ID) of the application. |
Example
The following example demonstrates how to use the CACHE_PURGE_BY_APPLICATION procedure to purge all the cached pages and regions for the application currently executing.
BEGIN
APEX_UTIL.CACHE_PURGE_BY_APPLICATION(p_application => :APP_ID);
END;
This procedure purges the cache for a given application and page. If the page itself is not cached but contains one or more cached regions, then the cache for these will also be purged.
Syntax
APEX_UTIL.CACHE_PURGE_BY_PAGE (
p_application IN NUMBER,
p_page IN NUMBER,
p_user_name IN VARCHAR2 DEFAULT NULL);
Parameters
Table 1-4 describes the parameters available in the CACHE_PURGE_BY_PAGE procedure.
Table 1-4 CACHE_PURGE_BY_PAGE Parameters
| Parameter | Description |
|---|---|
|
|
The identification number (ID) of the application. |
|
|
The page number (ID). |
|
|
The user associated with cached pages and regions. |
Example
The following example demonstrates how to use the CACHE_PURGE_BY_PAGE procedure to purge the cache for page 9 of the application currently executing. Additionally, if the p_user_name parameter is supplied, this procedure would be further restricted by a specific users cache (only relevant if the cache is set to be by user).
BEGIN
APEX_UTIL.CACHE_PURGE_BY_PAGE(
p_application => :APP_ID,
p_page => 9);
END;
This procedure deletes all cached pages and regions for a specified application that have passed the defined active time period. When you cache a page or region, you specify an active time period (or Cache Timeout). Once that period has passed, the cache will no longer be used, thus removing those unusable pages or regions from the cache.
Syntax
APEX_UTIL.CACHE_PURGE_STALE (
p_application IN NUMBER);
Parameters
Table 1-5 describes the parameters available in the CACHE_PURGE_STALE procedure.
Table 1-5 CACHE_PURGE_STALE Parameters
| Parameter | Description |
|---|---|
|
|
The identification number (ID) of the application. |
Example
The following example demonstrates how to use the CACHE_PURGE_STALE procedure to purge all the stale pages and regions in the application currently executing.
BEGIN
APEX_UTIL.CACHE_PURGE_STALE(p_application => :APP_ID);
END;
This procedure changes the password of the currently authenticated user, assuming Application Express user accounts are in use.
Syntax
APEX_UTIL.CHANGE_CURRENT_USER_PW(
p_new_password IN VARCHAR2);
Parameters
Table 1-6 describes the parameters available in the CHANGE_CURRENT_USER_PW procedure.
Table 1-6 CHANGE_CURRENT_USER_PW Parameters
| Parameter | Description |
|---|---|
|
|
The new password value in clear text |
Example
The following example demonstrates how to use the CHANGE_CURRENT_USER_PW procedure to change the password for the user who is currently authenticated, assuming Application Express accounts are in use.
BEGIN
APEX_UTIL.CHANGE_CURRENT_USER_PW ('secret99');
END;
Enables a developer to check whether this property is enabled or disabled for an end user account. This function returns true if the account password must be changed upon first use (after successful authentication) after the password is initially set and after it is changed on the Administration Service, Edit User page. This function returns false if the account does not have this property.
This function may be run in a page request context by any authenticated user.
Syntax
APEX_UTIL.CHANGE_PASSWORD_ON_FIRST_USE (
p_user_name IN VARCHAR2)
RETURN BOOLEAN;
Parameters
Table 1-7 describes the parameters available in the CHANGE_PASSWORD_ON_FIRST_USE function.
Table 1-7 CHANGE_PASSWORD_ON_FIRST_USE Parameters
| Parameter | Description |
|---|---|
|
|
The user name of the user account |
Example
The following example demonstrates how to use the CHANGE_PASSWORD_ON_FIRST_USE function. Use this function to check if the password of an Application Express user account (workspace administrator, developer, or end user) in the current workspace must be changed by the user the first time it is used.
BEGIN
FOR c1 IN (SELECT user_name FROM wwv_flow_users) LOOP
IF APEX_UTIL.CHANGE_PASSWORD_ON_FIRST_USE(p_user_name => c1.user_name) THEN
htp.p('User:'||c1.user_name||' requires password to be changed the first time it is used.');
END IF;
END LOOP;
END;
This procedure removes session state for a given application for the current session.
Syntax
APEX_UTIL.CLEAR_APP_CACHE (
p_app_id IN VARCHAR2 DEFAULT NULL);
Parameters
Table 1-8 describes the parameters available in the CLEAR_APP_CACHE procedure.
Table 1-8 CLEAR_APP_CACHE Parameters
| Parameter | Description |
|---|---|
|
|
The ID of the application for which session state will be cleared for current session |
Example
The following example demonstrates how to use the CLEAR_APP_CACHE procedure to clear all the current sessions state for the application with an ID of 100.
BEGIN
APEX_UTIL.CLEAR_APP_CACHE('100');
END;
This procedure removes session state for a given page for the current session.
Syntax
APEX_UTIL.CLEAR_PAGE_CACHE (
p_page IN NUMBER DEFAULT NULL);
Parameters
Table 1-9 describes the parameters available in the CLEAR_PAGE_CACHE procedure.
Table 1-9 CLEAR_PAGE_CACHE Parameters
| Parameter | Description |
|---|---|
|
|
The ID of the page in the current application for which session state will be cleared for current session. |
Example
The following example demonstrates how to use the CLEAR_PAGE_CACHE procedure to clear the current session s state for the page with an ID of 10.
BEGIN
APEX_UTIL.CLEAR_PAGE_CACHE('10');
END;
This procedure removes session state and application system preferences for the current user's session. Run this procedure if you reuse session IDs and want to run applications without the benefit of existing session state.
Syntax
APEX_UTIL.CLEAR_USER_CACHE;
Parameters
None.
Example
The following example demonstrates how to use the CLEAR_USER_CACHE procedure to clear all session state and application system preferences for the current user's session.
BEGIN
APEX_UTIL.CLEAR_USER_CACHE;
END;
This procedure counts clicks from an application built in Application Builder to an external site. You can also use the shorthand version, procedure Z, in place of APEX_UTIL.COUNT_CLICK.
Syntax
APEX_UTIL.COUNT_CLICK (
p_url IN VARCHAR2,
p_cat IN VARCHAR2,
p_id IN VARCHAR2 DEFAULT NULL,
p_user IN VARCHAR2 DEFAULT NULL,
p_workspace IN VARCHAR2 DEFAULT NULL);
Parameters
Table 1-10 describes the parameters available in the COUNT_CLICK procedure.