You are on page 1of 9

Persistent State of Packages The collection of public and private package variables represents the package st ate for

the user session That is, the package state is the set of values stored in all the package variables at a given point in time In general, the package st ate exists for the life of the user session Package variables are initialized the first time a package is loaded into memory for a user session The package variables are, by default, unique to each sessio n and hold their values until the user session is terminated In other words, the variables are stored in the User Global Area (UGA) memory allocated by the data base for each user session The package state changes when a package subprogram i s invoked and its logic modifies the variable state Public package state can be directly modified by operations appropriate to its type PRAGMA signifies that the statement is a compiler directive PRAGMAs are processe d at compile time, not at run time They do not affect the meaning of a program; they simply convey information to the compiler If you add PRAGMA SERIALLY_RESUAB LE to the package specification, then the database stores package variables in t he System Global Area (SGA) shared across user sessions In this case, the packag e state is maintained for the life of a subprogram call or a single reference to a package construct The SERIALLY_REUSABLE directive is useful if you want to co nserve memory and if the package state does not need to persist for each user se ssion This PRAGMA is appropriate for packages that declare large temporary work areas that are used once and not needed during subsequent database calls in the same s ession You can mark a bodiless package as serially reusable If a package has a spec and body, you must mark both You cannot mark only the body. The global memory for serially reusable packages is pooled in the System Global Area (SGA), not allocated to individual users in the User Global Area (UGA) That way, the package work area can be reused When the call to the server ends, the memory is returned to the pool Each time the package is reused, its public varia bles are initialized to their default values or to NULL Note: Serially reusable packages cannot be accessed from database triggers or ot her PL/SQL subprograms that are called from SQL statements If you try, the Oracl e server generates an error CREATE or REPLACE PACKAGE pkg1 IS PRAGMA SERIALLY_REUSABLE; num NUMBER := 0; PROCEDURE init_pkg_state(n NUMBER); PROCEDURE print_pkg_state; END pkg1; / CREATE or REPLACE PACKAGE BODY pkg1 IS PRAGMA SERIALLY_REUSABLE; PROCEDURE init_pkg_state (n NUMBER) IS BEGIN pkg1.num := n; dbms_output.put_line('Num: ' pkg1.num); END; PROCEDURE print_pkg_state IS BEGIN dbms_output.put_line('Num: ' pkg1.num); END; END pkg1; /

exec pkg1.init_pkg_state(10); exec pkg1.print_pkg_state; output: without PRAGMA SERIALLY_REUSABLE; Num: 10 Num: 10 with PRAGMA SERIALLY_REUSABLE; Num: 10 Num: 0 ************************************************* DBMS_OUTPUT provides debugging and buffering of text data. UTL_FILE enables reading and writing of operating system text files. UTL_MAIL enables composing and sending of email messages. DBMS_ALERT supports asynchronous notification of database events. Messages or al erts are sent on a COMMIT command. DBMS_LOCK is used to request, convert, and release locks through Oracle Lock Man agement services. DBMS_SESSION enables programmatic use of the ALTER SESSION SQL statement and oth er session-level commands. DBMS_APPLICATION_INFO can be used with Oracle Trace and the SQL trace facility t o record names of executing modules or transactions in the database for later us e when tracking the performance of various modules and debugging. HTP package writes HTML-tagged data into database buffers. DBMS_SCHEDULER enables scheduling and automated execution of PL/SQL blocks, stor ed procedures, and external procedures and executables

You might also like