简体   繁体   English

MySQL错误1064:存储过程

[英]MySQL Error 1064 : Stored procedure

thanks, It's work 谢谢,这是工作

It was on this 2 line : 这是在这两行:

SET valueName = CONCAT(valueName, ' ,', _valueSplit);
SET valueValue = CONCAT(valueValue,' ,', json(_entryData, _valueSplit));

I have declared the variable, but at NULL so CONCAT return NULL and the query go on NULL to 我已经声明了变量,但是在NULL时,因此CONCAT返回NULL并且查询继续为NULL

thanks to Devart for helping me 感谢Devart帮助我


the post : 帖子:

when I try to use my Stored Procedure I have this error 当我尝试使用我的存储过程时,我有这个错误

call _extract() Error Code: 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 'NULL' at line 1

but I see nothing in the procedure this my procedure, but no instruction NULL on it 但我在程序中看不到这个程序,但是没有指令NULL

CREATE PROCEDURE _extract()
BEGIN
    DECLARE _entryType VARCHAR(45);
    DECLARE _entryData VARCHAR(1024);
    DECLARE _entryTime BIGINT(20);

    DECLARE no_more_rows BOOLEAN;
    DECLARE num_rows INT DEFAULT 0;

    DECLARE entryCursor CURSOR FOR SELECT entryValue, entryTime FROM TrackingEntry;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_rows = TRUE;

    OPEN entryCursor;
    select FOUND_ROWS() into num_rows;

    mainLoop: LOOP

        FETCH entryCursor INTO _entryData, _entryTime;

        IF no_more_rows THEN
            CLOSE entryCursor;
            LEAVE mainLoop;
        END IF;

        SET _entryType = json(_entryData, "type");
        CALL split_string(json(_entryData, "data"), ",");
        CALL _extractJson(_entryType, _entryData);

    END LOOP mainLoop;
END$$

_extractJson procedure : the next part of the extration of the data _extractJson程序:数据的下一部分

CREATE PROCEDURE _extractJson(`_entryType` VARCHAR(255))
BEGIN

    DECLARE _valueSplit VARCHAR(255);

    DECLARE valueName VARCHAR(255);
    DECLARE valueValue VARCHAR(255);

    DECLARE split_no_more_rows BOOLEAN;
    DECLARE split_num_rows INT DEFAULT 0;

    DECLARE splitCursor CURSOR FOR SELECT SQL_CALC_FOUND_ROWS _value FROM SplitValues;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET split_no_more_rows = TRUE;

    OPEN splitCursor;
    select FOUND_ROWS() into split_num_rows;
    dataLoop: LOOP
        FETCH splitCursor INTO _valueSplit;
        IF split_no_more_rows THEN
            CLOSE splitCursor;
            LEAVE dataLoop;
        END IF;

        SET valueName = CONCAT(valueName, ' ,', _valueSplit);
        SET valueValue = CONCAT(valueValue,' ,', json(_entryData, _valueSplit));

    END LOOP dataLoop;
    SET @query = CONCAT('INSERT INTO ',_entryType, ' (',valueName,') VALUES (',valueValue,')' );
    PREPARE stmt FROM @query;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    --end stuffs here
END$$

to explain what i want to do 解释我想做什么

some Data are stored in trackingEntry, each row contain information about what the user do (in a social game) and where he come from (action, referer, and some other value) 一些数据存储在trackingEntry中,每行包含有关用户执行操作的信息(在社交游戏中)以及他来自何处(操作,引用和其他一些值)

theses data are stored in a Json format like that : { "type" : "tableName", "data" : "row1,row2,row3", "row1" : "value", "row2" : "value", "row3" : "value" } 这些数据以Json格式存储,如:{“type”:“tableName”,“data”:“row1,row2,row3”,“row1”:“value”,“row2”:“value”,“row3” “:”价值“}

the type of the data (the action (connection, publish on wall)) it's a table's name of one of our dashboard application 数据的类型(动作(连接,在墙上发布))它是我们的仪表板应用程序之一的表名

The "data" is the list of the available datas “数据”是可用数据的列表

and after we have the Datas 在我们拥有数据之后

You have to add SQL_CALC_FOUND_ROWS in the select statement, so that the FOUND_ROWS() function works. 您必须在select语句中添加SQL_CALC_FOUND_ROWS ,以便FOUND_ROWS()函数起作用。

So change this line 所以改变这一行

DECLARE entryCursor CURSOR FOR SELECT entryValue, entryTime FROM TrackingEntry;

like this 像这样

DECLARE entryCursor CURSOR FOR SELECT SQL_CALC_FOUND_ROWS entryValue, entryTime FROM TrackingEntry;

You can read more about it here . 你可以在这里阅读更多相关信息。

The problem can be with a prepared INSERT statement, it seems that one of the variables is NULL. 问题可以是用一个准备好的INSERT语句,似乎其中一个变量是NULL。 Try to comment prepared statements and select @query, you will see the problem - 尝试评论准备好的语句并选择@query,你会看到问题 -

SET @query = CONCAT('INSERT INTO ',_entryType, ' (',valueName,') VALUES (',valueValue,')' );
SELECT @query;
-- PREPARE stmt FROM @query;
-- EXECUTE stmt;
-- DEALLOCATE PREPARE stmt;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM