SQL, missing the end, but why?

I have a problem with my SQL procedure. MySQLWorkbench advises me to skip the "end" before my first SET, but not for the second. I do not know why.

DELIMITER $ drop procedure if exists pay10percent$ create procedure pay10percent(IN montant decimal(9,2),IN idResa INT(5)) begin declare circuitid INT; SET circuitid = ( SELECT IDCIRCUIT FROM RESERVATION WHERE IDRESERVATION=idResa ); declare montantCircuit decimal(9,2); SET montantCircuit = (SELECT PRIX FROM CIRCUIT WHERE IDCIRCUIT=circuitid); end; $ DELIMITER ; 

Thanks.

+5
source share
1 answer

Before using SET , all variables must be declared. Alternatively, you can opt out of SET and use this subquery as the default value:

 declare circuitid INT DEFAULT ( SELECT IDCIRCUIT FROM RESERVATION WHERE IDRESERVATION=idResa ); 
+4
source

All Articles