Common SQL Errors

MySQL Error 1320: ER_SP_NORETURN – No RETURN found in FUNCTION

Galaxy Team
August 6, 2025

This error appears when a MySQL stored function lacks a reachable RETURN statement on every execution path.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1320 ER_SP_NORETURN?

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.

Error Highlights

Typical Error Message

No RETURN found in FUNCTION %s

Error Type

Stored Routine Error

Language

MySQL

Symbol

ER_SP_NORETURN

Error Code

1320

SQL State

42000

Explanation

Table of Contents

What does MySQL Error 1320 mean?

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.

When does ER_SP_NORETURN surface?

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.

Why is fixing it important?

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.

Common Causes

Missing RETURN statement

The function ends with END without a RETURN clause, causing an immediate compilation failure.

Conditional branches without RETURN

Some IF, CASE, or LOOP branches exit without issuing RETURN, so MySQL sees unreachable returns in certain paths.

Unhandled exceptions

SIGNAL or RESIGNAL statements fire before a RETURN, making MySQL think normal execution may finish with no value.

Copying procedure code into a function

Developers sometimes paste procedure logic into a function and forget to add the mandatory RETURN.

Related Errors

Error 1415 - Not allowed to return a result set from a function

Occurs when SELECT without INTO appears inside a function. Returns and result sets are separate concepts.

Error 1336 - Definer not fully qualified

Triggers when the DEFINER clause in CREATE FUNCTION lacks host information.

Error 1054 - Unknown column

Raised when a column referenced inside the function body does not exist, often after schema changes.

FAQs

Do I need RETURN in a stored procedure?

No. RETURN is mandatory only in stored functions. Procedures can use LEAVE or simply END.

Can I return multiple values?

A function returns a single scalar value. To return multiple values, use OUT parameters in a procedure or return a JSON string.

Will SET sql_mode affect this error?

sql_mode does not change the requirement for RETURN in functions. The rule is enforced regardless of current modes.

How does Galaxy help avoid ER_SP_NORETURN?

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.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo