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.

Example:

create procedure proc_return
begin
  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;
  else
    return 0;
  end if;

end!

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