The CREATE PROCEDURE statement defines a procedure that is stored in the database.
This statement can be executed from the DB2® command line processor (CLP), any supported interactive SQL interface, an application, or a routine.
The authorization ID of the statement must be the owner of the matched procedure if OR REPLACE is specified (SQLSTATE 42501).
>>-CREATE--+------------+--PROCEDURE----------------------------> '-OR REPLACE-' >--+-----------------------------------------------------------------------------+--> '-(--+-------------------------------------------------------------------+--)-' | .-,-------------------------------------------------------------. | | V .-IN-----. | | '---parameter-name--+--------+--data-type--+--------------------+-+-' +-OUT----+ '-| default-clause |-' '-IN OUT-' .-----------------. V | >--+----------------+--+-IS-+----+-------------+-+--------------> '-READS SQL DATA-' '-AS-' '-declaration-' .-----------. V | >--BEGIN----statement-+-----------------------------------------> >--+----------------------------------------------------------------------------+--> | .-------------------------------------------------------------. | | | .-------------------. .-----------. | | | V V | V | | | '-EXCEPTION----WHEN--exception----+---------------+-+--THEN----statement-+-+-' '-OR--exception-' >--END--+----------------+------------------------------------->< '-procedure-name-'
The name (including an implicit or explicit qualifier), together with the number of parameters, must not identify a procedure that is described in the catalog (SQLSTATE 42723). The unqualified name, together with the number of parameters, is unique within its schema, but does not need to be unique across schemas.
The CREATE PROCEDURE statement can be submitted in obfuscated form. In an obfuscated statement, only the procedure name is readable. The rest of the statement is encoded in such a way that it is not readable, but can be decoded by the database server. Obfuscated statements can be produced by calling the DBMS_DDL.WRAP function.
CREATE OR REPLACE PROCEDURE simple_procedure
IS
BEGIN
DBMS_OUTPUT.PUT_LINE('That''s all folks!');
END simple_procedure;
CREATE OR REPLACE PROCEDURE test_goto
( p1 IN INTEGER, out1 OUT VARCHAR2(30) )
IS
BEGIN
<<LABEL2ABOVE>>
IF p1 = 1 THEN
out1 := out1 || 'one';
GOTO LABEL1BELOW;
END IF;
if out1 IS NULL THEN
out1 := out1 || 'two';
GOTO LABEL2ABOVE;
END IF;
out1 := out1 || 'three';
<<LABEL1BELOW>>
out1 := out1 || 'four';
END test_goto;