Stored procedures can be written in COBOL, PL/1, REXX and Java etc. Db2 stored procedures are handled by WLM -work Load Manager. Main uses are reusability and security.
Stored Procedure Flow
Note: The language to write stored procedure can be SQL, COBOL, PL/1 and JAVA. It runs in the database (in our case DB2). It needs an input and it gives you output after running it.
DB2 Stored Procedure Example
CREATE PROCEDURE UPDATE_SALARY (IN EMPLOYEE_NUM CHAR(6), IN RATE1 DECIMAL(5,2)) LANGUAGE SQL WLM ENVIRONMENT SAMP1 COMMIT ON RETURN YES IF RATE1 <= 0.7 THEN UPDATE EMP SET SALARY = SALARY * RATE1 WHERE EMPNO= EMPLOYEE_NUM; ELSE UPDATE EMP SET SALARY = SALARY * 0.7 WHERE EMPNO = EMPLOYEE_NUM; END IF
Here you passed three arguments to Stored Procedure IN- Input, OUT-Output INOUT-Input and output.