Customizing precompile and bind options for compiled SQL objects
The precompile and bind options for SQL procedures, compiled functions, compiled triggers and compound SQL (compiled) statements can be customized via a Db2® registry variable or some SQL procedure routines.
About this task
db2set DB2_SQLROUTINE_PREPOPTS=options
The options can be changed at the procedure level with the SET_ROUTINE_OPTS stored procedure. The values of the options set for the creation of SQL procedures in the current session can be obtained with the GET_ROUTINE_OPTS function.
The options used to compile a given routine are stored in the system catalog table ROUTINES.PRECOMPILE_OPTIONS, in the row corresponding to the routine. If the routine is revalidated, those stored options are also used during the revalidation.
After a routine is created, the compile options can be altered using the SYSPROC.ALTER_ROUTINE_PACKAGE and SYSPROC.REBIND_ROUTINE_PACKAGE procedures. The altered options are reflected in the ROUTINES_PRECOMPILE_OPTIONS system catalog table.
Example
The SQL procedures used in this example will be defined in following CLP scripts. These scripts are not in the sqlpl samples directory, but you can easily create these files by cutting-and-pasting the CREATE procedure statements into your own files.
db2 connect to sample
db2 CREATE TABLE expenses(amount DOUBLE, date DATE)
db2 connect reset
db2set DB2_SQLROUTINE_PREPOPTS="DATETIME ISO"
db2stop
db2start
Stopping and restarting the Db2 instance is necessary
for the change to take affect. db2 connect to sample
CREATE PROCEDURE maxamount(OUT maxamnt DOUBLE)
BEGIN
SELECT max(amount) INTO maxamnt FROM expenses;
END @
It will be created with options DATETIME
ISO and ISOLATION UR: db2 "CALL SET_ROUTINE_OPTS(GET_ROUTINE_OPTS() || ' ISOLATION UR')"
db2 -td@ -vf maxamount.db2
CREATE PROCEDURE fullamount(OUT fullamnt DOUBLE)
BEGIN
SELECT sum(amount) INTO fullamnt FROM expenses;
END @
It will be created with option ISOLATION
CS (note that it is not using the instance-wide DATETIME
ISO setting in this case): CALL SET_ROUTINE_OPTS('ISOLATION CS')
db2 -td@ -vf fullamount.db2
CREATE PROCEDURE perday()
BEGIN
DECLARE cur1 CURSOR WITH RETURN FOR
SELECT date, sum(amount)
FROM expenses
GROUP BY date;
OPEN cur1;
END @
The last SET_ROUTINE_OPTS call uses the NULL
value as the argument. This restores the global setting specified
in the DB2_SQLROUTINE_PREPOPTS registry, so the
last procedure will be created with option DATETIME ISO: CALL SET_ROUTINE_OPTS(NULL)
db2 -td@ -vf perday.db2