Create database in mysql

Asked

Viewed 6,739 times

0

I am trying to create the second precedure in mysql, but when I enter the first line of the declare 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

1 answer

2


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

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 ;
  • The following error appeared when I went to test ERROR 1064 (42000): 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 ';

  • You replaced the tag [sua_tabela]? Pq in question you did not put there did not know the name

  • I had one ; the most.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.