RETURN is a control-flow statement used inside stored procedures, stored functions, and trigger bodies. When the statement executes, the current routine stops immediately and execution control is passed back to the caller. If the dialect supports it, an expression can be supplied so that the routine returns a specific scalar value (often an integer status code or the function result). In PostgreSQL, MySQL, and Oracle PL/SQL the expression becomes the function’s result. In SQL Server, the optional integer expression becomes the stored procedure’s status code. If no value is supplied, the routine returns NULL or zero depending on the dialect. RETURN cannot be used in ad-hoc SQL outside of a routine, and it only returns one scalar value. To return result sets, dialect-specific constructs such as RETURN QUERY (PostgreSQL) or SELECT statements must be used.
expression
(any scalar) - Optional. The value sent back to the caller.Oracle PL/SQL (1992) and SQL Server 6.0 (1995)
RETURN stops the routine and returns a single scalar value. RETURN NEXT (PostgreSQL) appends a row to the function’s result set and continues execution.
No. RETURN only works inside stored procedures, functions, or trigger bodies. Using it elsewhere raises a syntax error.
The routine exits immediately. SQL Server returns 0, PostgreSQL and MySQL return NULL, unless the function is declared with RETURNS void.
Use dialect-specific mechanisms such as SELECT statements inside the routine, output parameters, table-valued functions, or PostgreSQL’s RETURN QUERY.