这个MYSQL查询有什么问题?

时间:2022-05-18 00:07:51
delimiter |

CREATE FUNCTION BASE64_DECODE (input BLOB)
        RETURNS BLOB
        CONTAINS SQL
        DETERMINISTIC
        SQL SECURITY INVOKER
BEGIN
        DECLARE ret BLOB DEFAULT '';
        DECLARE done TINYINT DEFAULT 0;

        IF input IS NULL THEN
                RETURN NULL;
        END IF;

each_block:
        WHILE NOT done DO BEGIN
                DECLARE accum_value BIGINT UNSIGNED DEFAULT 0;
                DECLARE in_count TINYINT DEFAULT 0;
                DECLARE out_count TINYINT DEFAULT 3;

each_input_char:
                WHILE in_count < 4 DO BEGIN
                        DECLARE first_char CHAR(1);

                        IF LENGTH(input) = 0 THEN
                                RETURN ret;
                        END IF;

                        SET first_char = SUBSTRING(input,1,1);
                        SET input = SUBSTRING(input,2);

                        BEGIN
                                DECLARE tempval TINYINT UNSIGNED;
                                DECLARE error TINYINT DEFAULT 0;
                                DECLARE base64_getval CURSOR FOR SELECT val FROM base64_data WHERE c = first_char;
                                DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET error = 1;

                                OPEN base64_getval;
                                FETCH base64_getval INTO tempval;
                                CLOSE base64_getval;

                                IF error THEN
                                        ITERATE each_input_char;
                                END IF;

                                SET accum_value = (accum_value << 6) + tempval;
                        END;

                        SET in_count = in_count + 1;

                        IF first_char = '=' THEN
                                SET done = 1;
                                SET out_count = out_count – 1;
                        END IF;
                END; END WHILE;

                WHILE out_count > 0 DO BEGIN
                        SET ret = CONCAT(ret,CHAR((accum_value & 0xff0000) >> 16));
                        SET out_count = out_count – 1;
                        SET accum_value = (accum_value << 8) & 0xffffff;
                END; END WHILE;

        END; END WHILE;

        RETURN ret;
END |

The error I'm getting is:

我得到的错误是:

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 '– 1;
                        END IF;
                END; END WHILE;
         ' at line 52

3 个解决方案

#1


3  

WHILE loops in MySQL are simply terminated with END WHILE;. You've got END; END WHILE; which is incorrect.

MySQL中的WHILE循环只是以END WHILE;终止。你已经结束了;结束时间;哪个不对。

#2


0  

That END before END WHILE; is causing the problem. You already have an END on line 46, so this one is trying to end the function. I'll bet you can just remove it.

在END WHILE之前结束;造成了这个问题。你已经在第46行有一个END,所以这个试图结束这个功能。我打赌你可以删除它。

#3


0  

The problem, silly as it was, was the use of non-standard symbols throughout. -s and 's were wrong format. Due to the encoding of the IDE I am using or something just as silly.

这个问题虽然很愚蠢,但始终使用非标准符号。 -s和's格式错了。由于我正在使用的IDE的编码或者同样愚蠢的东西。

facepalm

捂脸

#1


3  

WHILE loops in MySQL are simply terminated with END WHILE;. You've got END; END WHILE; which is incorrect.

MySQL中的WHILE循环只是以END WHILE;终止。你已经结束了;结束时间;哪个不对。

#2


0  

That END before END WHILE; is causing the problem. You already have an END on line 46, so this one is trying to end the function. I'll bet you can just remove it.

在END WHILE之前结束;造成了这个问题。你已经在第46行有一个END,所以这个试图结束这个功能。我打赌你可以删除它。

#3


0  

The problem, silly as it was, was the use of non-standard symbols throughout. -s and 's were wrong format. Due to the encoding of the IDE I am using or something just as silly.

这个问题虽然很愚蠢,但始终使用非标准符号。 -s和's格式错了。由于我正在使用的IDE的编码或者同样愚蠢的东西。

facepalm

捂脸