Create procedure in mysql

0

I'm trying to create the second precedence in mysql, but when I give the enter in the first line of the declare it gives the following error:

ERROR 1064 (42000)

CREATE PROCEDURE finaliza_expedicao (IN expedicao_id INT)
    BEGIN
    DECLARE id_prod INT;
    DECLARE id_conf INT;
    DECLARE id_int INT;

        SELECT id INTO id_prod FROM expedicao WHERE codigo = expedicao_id;
    SELECT conferencia_id INTO id_conf FROM separacao WHERE expedicao_id = id_prod;
        SELECT interno_id INTO id_int WHERE conferencia_id = id_conf
    UPDATE volume SET contido_em_id = NULL, area_id = NULL, expedicao_id = id_prod 

WHERE id = id_int;
    UPDATE expedicao SET data_fim = DATE_FORMAT(NOW(), '%Y-%m-%d H:i:s') WHERE id = 

id_prod;
    END
    
asked by anonymous 06.12.2017 / 19:56

1 answer

1

Missing from table in one of your variable assignments, always try to better indent the code for better readability and even find the errors, follow the code, just change the [sua_tabela] tag to the table that belongs to the query.

DROP PROCEDURE IF EXISTS finaliza_expedicao;
DELIMITER |
CREATE PROCEDURE finaliza_expedicao (IN expedicao_id INT)
BEGIN

    DECLARE id_prod INT;
    DECLARE id_conf INT;
    DECLARE id_int INT;

    SELECT 
                id 
        INTO id_prod 
        FROM expedicao 
        WHERE codigo = expedicao_id;

    SELECT 
                conferencia_id 
        INTO id_conf 
        FROM separacao 
        WHERE expedicao_id = id_prod;

        SELECT 
                    interno_id  
        INTO id_int 
        FROM [sua_tabela]
        WHERE conferencia_id = id_conf;

    UPDATE volume 
                SET contido_em_id = NULL, 
                        area_id = NULL, 
                        expedicao_id = id_prod 
        WHERE id = id_int;

        UPDATE expedicao 
                SET data_fim = DATE_FORMAT(NOW(), '%Y-%m-%d H:i:s') 
        WHERE id = id_prod;
END
|
DELIMITER ;
    
07.12.2017 / 14:52