Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL, missing end, but why?

I have an issue with my SQL procedure. MySQLWorkbench advise me that it miss 'end' to my first SET, but not for the second. I don't 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.

like image 972
Romain Caron Avatar asked Jun 18 '15 13:06

Romain Caron


1 Answers

You must declare all the variables before using SET. Alternatively, you can drop SET and use that subquery as a default value:

declare circuitid INT DEFAULT (
    SELECT IDCIRCUIT  
    FROM RESERVATION 
    WHERE IDRESERVATION=idResa
);
like image 192
Federico Razzoli Avatar answered Sep 25 '22 14:09

Federico Razzoli