Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.1 » SQL Anywhere Server - SQL Usage » Stored procedures, triggers, batches, and user defined functions » The structure of procedures, triggers, and user-defined functions


Ways to pass parameters to procedures

You can take advantage of default values of stored procedure parameters with either of two forms of the CALL statement.

If the optional parameters are at the end of the argument list in the CREATE PROCEDURE statement, they may be omitted from the CALL statement. As an example, consider a procedure with three INOUT parameters:

CREATE PROCEDURE SampleProcedure( 
       INOUT var1 INT DEFAULT 1,
                     INOUT var2 int DEFAULT 2,
                     INOUT var3 int DEFAULT 3 )

This example assumes that the calling environment has set up three variables to hold the values passed to the procedure:


The procedure SampleProcedure may be called supplying only the first parameter as follows, in which case the default values are used for var2 and var3.

CALL SampleProcedure( V1 );

The procedure can also be called by providing only the second parameter by using the DEFAULT value for the first parameter, as follows:

CALL SampleProcedure( DEFAULT, V2 );

A more flexible method of calling procedures with optional arguments is to pass the parameters by name. The SampleProcedure procedure may be called as follows:

CALL SampleProcedure( var1 = V1, var3 = V3 );

or as follows:

CALL SampleProcedure( var3 = V3, var1 = V1 );