Comments - DECLARE Variable
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.
DECLAREs have to be the first things in a stored program. They can't be used somewhere in the middle, regardless that you're correctly using your local variables after the DECLARE. You cannot first do a SELECT or CREATE or anything like that. If you're going to use a local variable, DECLARE it right after you typed BEGIN.