602SQL Documentation Index  

RETURN Statement (SQL)

statement_RETURN ::= RETURN expression;

The RETURN statement sets the function value as the expression value. This statement must be called in a function body. The expression type must be assignable to the function result. The rules specified in the SET statement description are valid for the RETURN statement as well.

The RETURN statement may be present in the function body multiple times. One of the following possibilities will occur according to the compatibility attribute SQLOPT_REPEATABLE_RETURN setting:

The RETURN statement must be executed in the function body when a function is executed. If the RETURN statement is not executed, the error sqlstate 2F001 (SQ_NO_RETURN_IN_FNC) occurs.


FUNCTION maxnumber () RETURNS INT;  
  DECLARE maxval INT;  
  SELECT MAX(number)+1 INTO maxval FROM Tab1;  
  RETURN (maxval);