RETURN statement

The RETURN statement can be used to immediately terminating and leaving a stored procedure. Furthermore it can be used to return a status of a stored procedure. This return status you can check in the calling stored procedure by the GET DIAGNOSTICS statement.


create procedure proc_return
  declare num_rows int;

  set num_rows = (select count(*) from syscat.tables where tabschema <> 'SYSIBM' and type = 'T');

  if num_rows = 0 then
    return -1;
    return 0;
  end if;


Link to the DB2 Information Center: DB2 9.7 DB2 10.1 DB2 10.5