1313
MySQLerrorstored-procedureshigh confidence

FUNCTION ended without RETURN

Production Risk

Low — runtime error at execution; function returns NULL or errors.

What this means

A stored function execution reached the end of the function body without hitting a RETURN statement.

Why it happens
  1. 1RETURN only inside conditional branches, and execution fell through with no match
  2. 2Exception handler swallowed the error without returning
How to reproduce
trigger — this will error
trigger — this will error
CREATE FUNCTION f(x INT) RETURNS INT DETERMINISTIC BEGIN IF x > 0 THEN RETURN 1; END IF; END;

expected output

ERROR 1313 (2F005): FUNCTION f ended without RETURN

Fix

Add a default RETURN at function end

Add a default RETURN at function end
CREATE FUNCTION f(x INT) RETURNS INT DETERMINISTIC BEGIN IF x > 0 THEN RETURN 1; END IF; RETURN 0; END;

Why this works

Ensures execution always hits a RETURN regardless of branch.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1313 ER_SP_NORETURNEND

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors