DECLARE PROCEDURE

Top  Previous  Next

 

Syntax

<declare_procedure> ::=

  DECLARE PROCEDURE procedure_name (<input_parameter_clause>)

  [RETURNS (<output_parameter_clause>)]

  AS

  [<declare_clause>]

  BEGIN

    [<compound_statement>]

    [<when_do>]

  END

 

<input_parameter_clause> ::= <input_parameter_spec> [, <input_parameter_spec>]

 

<input_parameter_spec> ::= parameter_name <data_type> [NOT NULL] [{DEFAULT | = } value]

 

<output_parameter_clause> ::= <output_parameter_spec> [, <output_parameter_spec>]

 

<output_parameter_spec> ::= parameter_name <data_type>

 

<declare_clause> ::= { <declare_variable> | <declare_cursor> | <declare_subroutine> } [<declare_clause>]

 

<declare_subroutine> ::== { <declare_function> | <declare_procedure> }

 

<compound_statement> ::= { <block> | <statement> } [{ <block> | <statement> }]

 

As with the complete code block, this can have optional input parameters and a declare clause as well as multiple output parameters.

 

Example

execute udsblock(pin integer)

returns(pout integer, pout2 integer)

as

 

 declare procedure mult(i1 integer, i2 integer default 10) returns (out integer)

 as 

 begin

   out = i1 * i2;

 end

begin

  execute procedure mult(pin, 5) returning_values :pout;

  execute procedure mult(pin) returning_values :pout2;

end

 

In the example above, a procedure subroutine "mult" is declared that accepts 2 input parameters, 1 optional and a single output parameter.

 

The routine is then called twice, with a RETURNING_VALUES clause and named variables as the subroutine output targets.