Romain Caron
Romain Caron

Reputation: 257

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.

Upvotes: 6

Views: 4548

Answers (1)

Federico Razzoli
Federico Razzoli

Reputation: 5361

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
);

Upvotes: 5

Related Questions