This error appears when a MySQL stored function lacks a reachable RETURN statement on every execution path.
MySQL Error 1320: ER_SP_NORETURN occurs when a stored function has no reachable RETURN statement. Add a RETURN value in every code path, then recreate the function to resolve the issue.
No RETURN found in FUNCTION %s
Error 1320 (SQLSTATE 42000) tells MySQL that the stored function definition lacks a RETURN statement on at least one path. Because every MySQL function must produce a single scalar value, the absence of RETURN makes the routine invalid and prevents creation or invocation.
MySQL detects the problem at CREATE FUNCTION or ALTER FUNCTION time. If the server was upgraded or the routine edited externally, the error may instead appear when the function first executes.
The error surfaces during compilation of a new or altered function, during server restart when routines are parsed, or at runtime if the optimizer revalidates the stored routine. Any path that compiles the SQL body without finding a RETURN will trigger the exception.
A function that cannot compile blocks dependent queries and breaks application logic. Addressing the error quickly restores database integrity, ensures predictable return values, and avoids cascading failures in views, triggers, or application code that call the function.
The function ends with END without a RETURN clause, causing an immediate compilation failure.
Some IF, CASE, or LOOP branches exit without issuing RETURN, so MySQL sees unreachable returns in certain paths.
SIGNAL or RESIGNAL statements fire before a RETURN, making MySQL think normal execution may finish with no value.
Developers sometimes paste procedure logic into a function and forget to add the mandatory RETURN.
Occurs when SELECT without INTO appears inside a function. Returns and result sets are separate concepts.
Triggers when the DEFINER clause in CREATE FUNCTION lacks host information.
Raised when a column referenced inside the function body does not exist, often after schema changes.
No. RETURN is mandatory only in stored functions. Procedures can use LEAVE or simply END.
A function returns a single scalar value. To return multiple values, use OUT parameters in a procedure or return a JSON string.
sql_mode does not change the requirement for RETURN in functions. The rule is enforced regardless of current modes.
Galaxy’s real-time linting highlights missing RETURN statements while you type and auto-generates skeleton code with a default RETURN, preventing the error before execution.