3081
MySQLERRORCriticalStored RoutinesHIGH confidence

LIMIT clause requires an integer value

Production Risk

Low — the procedure call fails; no data is modified.

What this means

A stored procedure variable used in a LIMIT clause is not of an integer type.

Why it happens
  1. 1Using a VARCHAR or other non-integer stored procedure variable in LIMIT or OFFSET.
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE p(lim VARCHAR(10)) BEGIN SELECT * FROM t LIMIT lim; END;

expected output

ERROR 3081 (HY000): LIMIT clause uses a non-integer value.

Fix

Declare the LIMIT variable as an integer type

Declare the LIMIT variable as an integer type
CREATE PROCEDURE p(lim INT) BEGIN SELECT * FROM t LIMIT lim; END;

Why this works

LIMIT requires an integer; declaring it as INT avoids the type mismatch.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3081 ER_WRONG_SPVAR_TYPE_IN_LIMIT2

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

← All MySQL errors