5.7 Package initialization

 < Day Day Up > 



5.7 Package initialization

With Oracle you can define initialization in PL/SQL packages, which is executed only one time when starting a new database session. Example 5-25 shows the initialization within an Oracle package.

Example 5-25: Oracle package with initialization

start example
 CREATE OR REPLACE PACKAGE BODY pkg_init_v1 AS    -- function / procedure definition    -- ... -- Body initialization BEGIN    -- ... END pkg_init_v1; 
end example

In DB2 UDB, each SQL PL block is a function or procedure beginning with CREATE FUNCTION or CREATE PROCEDURE. MTK is able to convert the Example 5-25 if you define a procedure with the initialization commands.

Example 5-26 shows an alternative of Example 5-25 with the same behavior. In the initialization, part is now only the call of the procedure init, within init is the source of the initialization.

Example 5-26: Oracle package with initialization as procedure

start example
 CREATE OR REPLACE PACKAGE BODY pkg_init_v2 AS    -- function / procedure definition    -- ... -- initialization procedure PROCEDURE init IS BEGIN    -- ... END; -- Body initialization BEGIN    init; END pkg_init_v2; 
end example

Within your application, you have to add the call of the procedure init to perform the initialization every time you connect to the database.



 < Day Day Up > 



Oracle to DB2 UDB Conversion Guide2003
Oracle to DB2 UDB Conversion Guide2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 132

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net