1304
MariaDBerrorstored-procedureshigh confidence
RETURN is only allowed in a FUNCTION
Production Risk
Low — compile-time error; routine not created.
What this means
A RETURN statement was used inside a stored procedure or trigger instead of a function.
Why it happens
- 1Using RETURN in a CREATE PROCEDURE body
- 2Using RETURN in a trigger body
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE p() BEGIN RETURN 1; END;
expected output
ERROR 1304 (42000): RETURN is only allowed in a FUNCTION
Fix 1
Use an OUT parameter for procedures
Use an OUT parameter for procedures
CREATE PROCEDURE p(OUT result INT) BEGIN SET result = 1; END;
Why this works
Procedures return values via OUT/INOUT parameters.
Fix 2
Convert to a function
Convert to a function
CREATE FUNCTION f() RETURNS INT DETERMINISTIC RETURN 1;
Why this works
Functions use RETURN to yield a single value.
Sources
Official documentation ↗
MySQL 8.0 — 1304 ER_SP_BADRETURN
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev