3142
MariaDBERRORNotableStored RoutinesHIGH confidence

Conflicting declarations in stored program

Production Risk

Low — compile-time error; stored procedure is not created.

What this means

Two variable declarations in the same stored procedure or function block have conflicting definitions — either duplicate names or incompatible types that prevent compilation.

Why it happens
  1. 1Two DECLARE statements for the same variable name in the same BEGIN...END block.
  2. 2Handler or cursor declarations that conflict with existing variable names.
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE p() BEGIN
  DECLARE x INT;
  DECLARE x VARCHAR(10);
END;

expected output

ERROR 3142 (42000): Conflicting declarations: 'DECLARE x INT' and 'DECLARE x VARCHAR(10)'

Fix

Rename one of the conflicting declarations

Rename one of the conflicting declarations
CREATE PROCEDURE p() BEGIN
  DECLARE x INT;
  DECLARE y VARCHAR(10);
END;

Why this works

Unique variable names prevent the compilation conflict.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3142 ER_CONFLICTING_DECLARATIONS

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

← All MariaDB errors