There are two parts to any stored procedure:
A simple stored procedure requires only the procedure name in the specification and a statement that requires no parameters in the body, as shown in the following example. The procedure in the following example assumes a table called HelloWorldTBL exists, and inserts a string into that table.
A Simple Stored Procedure Example
CREATE PROCEDURE HelloWorld () |
Procedure Specification |
BEGIN SQLIStatement Insert_HelloWorld = new SQLIStatement ("INSERT INTO HelloWorldTBL(fld1) values ('Hello World!')"); Insert_HelloWorld.execute(); END |
Procedure Body |
From the Interactive SQL utility, isql, you could execute the procedure as follows:
ISQL> CREATE TABLE helloworldTBL (fld1 CHAR(100));
ISQL> CALL HelloWorld();
0 records returned
ISQL> SELECT * FROM helloworldTBL;
FLD1
----
Hello World!
1 record selected
The procedure specification can also contain other optional clauses:
Note: names specified in the result-set declaration are not used within the stored procedure body. Instead, methods of the FairCom DB SQL Java classes refer to fields in the result set by ordinal number, not by name.)
The following example shows a more complex procedure specification that contains these elements.
Complete Stored Procedure Example
Procedure Specification:
CREATE PROCEDURE new_sal(IN deptnum INTEGER, IN pct_incr INTEGER) |
Parameter declarations |
RESULT(empname CHAR(20), oldsal NUMERIC, newsal NUMERIC) |
Procedure result set declaration |
IMPORT import java.dbutils.SequenceType; |
Import clause |
Procedure Body:
BEGIN |
Body |