Your SQL procedures can contain CALL statements to call other SQL procedures. This feature, called nested stored procedures, enables you to reuse existing SQL procedures and design more complex applications.
To call a target SQL procedure from within a caller SQL procedure, simply include a CALL statement with the appropriate number and types of parameters in your caller. If the target returns OUT parameters, the caller can use the returned values in its own statements.
For example, you can create an SQL procedure that calls a target SQL procedure with the name "SALES_TARGET" and that accepts a single OUT parameter of type INTEGER with the following SQL:
CREATE PROCEDURE NEST_SALES(OUT budget DECIMAL(11,2)) LANGUAGE SQL BEGIN DECLARE total INTEGER DEFAULT 0; SET total = 6; CALL SALES_TARGET(total); SET budget = total * 10000; END
If a target SQL procedure returns result sets, either the caller or the client application receives the result sets, depending on the DECLARE CURSOR statements issued by the target SQL procedure. For each DECLARE CURSOR statement in the target that includes the WITH RETURN TO CLIENT clause, the caller does not receive the result set. For WITH RETURN TO CLIENT cursors, the result set is returned directly to the client application.
For more information on returning result sets from nested SQL procedures, see Returning Result Sets to Caller or Client.
Keep the following restrictions in mind when designing your application architecture:
An SQL procedure created with the NO SQL clause cannot issue a CALL statement.