1314
MariaDBerrorstored-procedureshigh confidence

Cursor statement must be a SELECT

Production Risk

Low — compile-time error; routine not created.

What this means

A cursor was declared with a statement that is not a SELECT (e.g. an UPDATE or CALL).

Why it happens
  1. 1Declaring CURSOR FOR UPDATE instead of SELECT
  2. 2Accidentally using a non-SELECT DML in a cursor definition
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE p() BEGIN DECLARE cur CURSOR FOR UPDATE t SET x=1; END;

expected output

ERROR 1314 (42000): Cursor statement must be a SELECT

Fix

Use SELECT in the cursor definition

Use SELECT in the cursor definition
DECLARE cur CURSOR FOR SELECT id FROM t;

Why this works

Cursors iterate over SELECT result sets only.

Sources
Official documentation ↗

MySQL 8.0 — 1314 ER_SP_BAD_CURSOR_QUERY

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

← All MariaDB errors