Universal Database (netDB2) Introductory GuideStored Procedure Language (SPL)An SQL procedure has a procedure body, which contains the source statements for the stored procedure. The following example shows a CREATE PROCEDURE statement for a simple stored procedure. The procedure name, the list of parameters that are passed to or from the procedure, and the LANGUAGE parameter are common to all stored procedures. However, the LANGUAGE value of SQL and the BEGIN...END block, which forms the procedure body, are particular to an SQL procedure. Once you have created stored procedures, you can call them from within application programs using the SQL CALL statement. You can also call SQL CALL statement from within the script center. Syntax:
('@') is used as the terminating character for stored procedures in NetDB2.
To test this stored procedure, first create the Employee table with the required attributes. You can then call the stored procedure from the script center using the following CALL statement.
The above procedure call will raise the salary of the employee with employee number 10666 to 500% of his/her current salary
The following example receives a department number as an input parameter. A WHILE statement in the procedure body fetches the salary and bonus for each employee in the department. An IF statement within the WHILE statement updates salaries for each employee depending on number of years of service and current salary. When all employee records in the department have been processed, the FETCH statement that retrieves employee records receives SQLSTATE 20000. A not_found condition handler makes the search condition for the WHILE statement false, so execution of the WHILE statement ends.
|
|
For any problems, questions or suggestions about this page please contact, Mario (espinoza@ics.uci.edu) |
rev. Dec. 24, 2001 |