Creating new versions of native SQL procedures
A new version of a native SQL procedure can have different parameter names, procedure options, or procedure body.
About this task
All versions of a procedure must have the same procedure signature. Therefore, each version of the procedure must have the same of the following items:
- Schema name
- Procedure name
- Number of parameters
- Data types for corresponding parameters
When any single version of a procedure is defined as autonomous, all versions must be defined as autonomous.
Procedure
- FL 507 The CREATE PROCEDURE statement with the following items:
- The OR REPLACE clause.
- The VERSION clause with a new version identifier.
- The ALTER PROCEDURE statement with the following items:
- The ADD VERSION clause with a name for the new version.
- The name of the native SQL procedure for which you want to create a new version.
- The parameter list of the procedure that you want to change. For ALTER PROCEUDRE ADD VERSION, this parameter list must be the same as the original procedure.
- Any procedure options. These options can be different than the options for other versions of this procedure. If you do not specify a value for a particular option, the default value is used, regardless of the value that is used by the current active version of this procedure.
- A procedure body. This body can be different than the procedure body for other versions of this procedure.
Examples
- Example 1
-
For example, the following CREATE PROCEDURE statement defines a new native SQL procedure called UPDATE_BALANCE. The version of the procedure is V1, and it is the active version.
CREATE PROCEDURE UPDATE_BALANCE (IN CUSTOMER_NO INTEGER, IN AMOUNT DECIMAL(9,2)) VERSION V1 LANGUAGE SQL READS SQL DATA BEGIN DECLARE CUSTOMER_NAME CHAR(20); SELECT CUSTNAME INTO CUSTOMER_NAME FROM ACCOUNTS WHERE CUSTNO = CUSTOMER_NO; END
- Example 2
-
The following ALTER PROCEDURE statement creates a new version of the UPDATE_BALANCE procedure. The version name of the new version is V2. This new version has a different procedure body.
ALTER PROCEDURE UPDATE_BALANCE ADD VERSION V2 (IN CUSTOMER_NO INTEGER, IN AMOUNT DECIMAL (9,2) ) MODIFIES SQL DATA BEGIN UPDATE ACCOUNTS SET BAL = BAL + AMOUNT WHERE CUSTNO = CUSTOMER_NO; END
- Example 3:
- FL 507
The following CREATE PROCEDURE statement with the OR REPLACE clause creates a new version of the UPDATE_BALANCE procedure, assuming that version V3 does not already exist (if V3 already exists, this statement would replace the existing definition). This version changes the procedure body in the same way as in Example 2:
CREATE OR REPLACE PROCEDURE UPDATE_BALANCE (IN CUSTOMER_NO INTEGER, IN AMOUNT DECIMAL(9,2)) VERSION V3 LANGUAGE SQL MODIFIES SQL DATA BEGIN UPDATE ACCOUNTS SET BAL = BAL + AMOUNT WHERE CUSTNO = CUSTOMER_NO; END