mardi 3 mars 2015

Clarification on usage of Serially Reusable Pragma for Oracle 10g


I need to make packages for Oracle 10g that can be changed while users are still logged in an using an application that makes database calls through PL/SQL. Unfortunately, anytime a package is updated while users are using it they get the following error:



ORA-04068: existing state of packages has been discarded


This makes it really difficult to make changes that are still compatible with the application that is using these PL/SQL packages.


I read that by using PRAGMA SERIALLY_REUSABLE the ORA-04068 error can be avoided.


After reading through lots of documentation, I keep stumbling upon the same warning for using the SERIALLY_REUSABLE pragma.



Serially reusable packages cannot be accessed from database triggers or other PL/SQL subprograms that are called from SQL statements.


The second half of this warning or other PL/SQL subprograms that are called from SQL statements is difficult to understand and I have not been able to find any examples through the Oracle website, Ask Tom, dba-oracle.com or any other website that provides information about Oracle products.


Question:

What are some examples for invalid usage of packages that implement the SERIALLY_REUSABLE pragma and will I be able to use this with client-side reference cursors?


Example Package 1



CREATE OR REPLACE PACKAGE example_package_1 AS
PRAGMA SERIALLY_REUSABLE;

FUNCTION get_database_system_time(
date_time_format IN VARCHAR
) RETURN VARCHAR;

END example_package_1;
/
CREATE OR REPLACE PACKAGE BODY example_package_1 AS
PRAGMA SERIALLY_REUSABLE;

--------------------------------------------------------
-- example 1
--------------------------------------------------------
FUNCTION get_database_system_time(
date_time_format IN VARCHAR
) RETURN VARCHAR AS return_value VARCHAR(256);
formatted_system_time VARCHAR(64);
BEGIN
SELECT
TO_CHAR(sysdate, date_time_format) INTO formatted_system_time
FROM
dual
;

RETURN formatted_system_time;
END get_database_system_time;
END example_package_1;


Example Package 2



CREATE OR REPLACE PACKAGE example_package_2 AS
PRAGMA SERIALLY_REUSABLE;

FUNCTION get_time(
locale IN VARCHAR
) RETURN VARCHAR;
END example_package_2;
/
CREATE OR REPLACE PACKAGE BODY example_package_2 AS
PRAGMA SERIALLY_REUSABLE;
--------------------------------------------------------
-- example 2
--------------------------------------------------------
FUNCTION get_time(
locale IN VARCHAR
) RETURN VARCHAR AS return_value VARCHAR(256);
formatted_time VARCHAR(64);
BEGIN
IF locale IS NOT NULL THEN
formatted_time := example_package_1.get_database_system_time('HH24:MI:SS');
END IF;

RETURN formatted_time;
END get_time;
END example_package_2;




Aucun commentaire:

Enregistrer un commentaire