1320
MySQLerrorstored-procedureshigh confidence

Incorrect number of FETCH variables

Production Risk

Low — compile-time error; routine not created.

What this means

The number of variables in a FETCH statement does not match the number of columns in the cursor SELECT.

Why it happens
  1. 1Cursor SELECT returns 3 columns but FETCH INTO only lists 2 variables
  2. 2Cursor definition was changed without updating the FETCH statement
How to reproduce
trigger — this will error
trigger — this will error
DECLARE cur CURSOR FOR SELECT a, b, c FROM t; FETCH cur INTO v1, v2;

expected output

ERROR 1320 (HY000): Incorrect number of FETCH variables

Fix

Match variable count to column count

Match variable count to column count
FETCH cur INTO v1, v2, v3;

Why this works

One variable per selected column.

Sources
Official documentation ↗

MySQL 8.0 — 1320 ER_SP_WRONG_NO_OF_FETCH_ARGS

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

← All MySQL errors