0
votes

What is wrong with "program" below that is preventing me from creating this stored procedure? Any help or clean up suggestions would be great.

DELIMITER $$
DROP PROCEDURE IF EXISTS baixa_estacio;
CREATE PROCEDURE baixa_estacio (IN id int(11))
BEGIN
    DECLARE estacio2 INT;
    DECLARE temps1 TIME(7);
    DECLARE dist1 FLOAT;
    DECLARE estacio1 INT;
    DECLARE estacio3 INT;
    DECLARE temps2 TIME(7);
    DECLARE dist2 FLOAT;
    SELECT id_estacioescomunica, temps, distancia INTO estacio2, temps1, dist1 FROM escomunica WHERE escomunica.id_estacioescomunica= id;
    SELECT id_estaciocomunicada,id_estacioescomunica,temps,distancia INTO estacio1,estacio3, temps2, dist2 FROM escomunica WHERE escomunica.id_estacioescomunicada = id;
    DELETE FROM escomunica WHERE ((id_estacioescomunica = id)  AND (EsTransbordament)=1);
    DELETE FROM escomunica WHERE ((id_estaciocomunicada = id) AND (EsTransbordament)=0);
    UPDATE escomunica SET id_estacioescomunica =  estacio3, temps = SEC_TO_TIME(( TIME_TO_SEC (temps1) + TIME_TO_SEC (temps2))), distancia - (dist1 + dist2) WHERE ((id_estacioescomunica-id)AND(estransbordament)=0);
    END;
    $$
    DELIMITER;

I dont know what could be wrong. The message error shows the next:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE PROCEDURE baixa_estacio (IN id INT) BEGIN DECLARE estacio2 INT; ' at line 2

1
You need to delimit the drop using $$ as you have changed the delimiter in the line before that.a_horse_with_no_name

1 Answers

0
votes

You have to terminate queries outsite sproc using the delimiter you defined. ie DROP PROCEDURE IF EXISTS baixa_estacio$$ not ";"