July 30, 2010, Friday, 210


Default Values

From SQL PL Guide for DB2

Jump to: navigation, search

Stored procedures in DB2 does not support default values. But there's a workaround available to specify default values: The input parameters must be test for NULL at the beginning of the procedure, output parameters must be checked before the procedure ends.

Example:

 CREATE PROCEDURE myproc (IN var01 INTEGER, OUT var02 INTEGER)
 BEGIN
    IF (p1 is null) THEN
       SET var01 = 0;
    END IF;

   ... code ...

    IF (p2 is null) THEN
       SET var02 = 0;
    END IF;

 END