1

I've created the following stored procedure:

CREATE DEFINER=`root`@`localhost` PROCEDURE `ABON_PLATA`(DATE_BAL1 datetime)
BEGIN
        DECLARE IMSI1 varchar(6);
        DECLARE DATE1 datetime;
        DECLARE ID_U1 integer;
        DECLARE PAY1 double;
        DECLARE PAYSUM double;
        DECLARE OLD1 double;
        DECLARE REASON1 varchar(16);
        DECLARE FLAG integer DEFAULT 0;
        DECLARE C1 CURSOR FOR SELECT ID_U FROM podkl_otkl_uslug WHERE IMSI1=IMSI;
        DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET FLAG=1;

OPEN C1;
     REPEAT
        FETCH C1 INTO ID_U1;
                IF FLAG=0 THEN
                SELECT SUM(PAY) INTO PAY1 FROM uslugi WHERE ID_U1=ID_U AND DATE_PODKL<DATE_BAL1 AND DATE_OTKL IS NULL;
                SET REASON1 = 'ABON PLATA';
                SET DATE1 = DATE_BAL1;
                SET PAYSUM = `NEW`-PAY1;
                SET OLD1 = `NEW`;
              END IF;
        INSERT history (`DATE`, REASON, `NEW`, OLD, IMSI) VALUES (DATE1, REASON1, PAYSUM, OLD1, IMSI1);
        UNTIL FLAG=1
     END REPEAT;
CLOSE C1;
END

It is used to simulate subscribtion fee of mobile operator. As I am trying to call it, I get the notorious error:

CALL ABON_PLATA(2013-07-07 12:00:00);

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 '12:00:00)' at line 1

Considering it is an error at line 1, I get extremely confused. What super obvious am I missing?

4

1 回答 1

0

日期时间文字必须用引号引起来。

CALL ABON_PLATA('2013-07-07 12:00:00');

它在第 1 行报告错误的原因是它是CALL包含错误的行。它与您的过程代码无关,因为错误发生在它甚至可以调用您的过程之前。


回复您的评论:

线程堆栈溢出:131072 字节堆栈使用了 6892 字节,需要 128000 字节。使用 'mysqld --thread_stack=#' 指定更大的堆栈。

这表明您的 MySQL 的配置值thread_stack太小而无法在存储过程中运行语句。例如,如果您使用与某些 MySQL 版本捆绑在一起的my-small.cnf配置文件,就会发生这种情况。

增加thread_stack配置文件中的值。默认为 256K,只有 my-small.cnf 将其设置得较低。已记录有关此设置太低的错误。

对配置文件进行此更改后,不要忘记重新启动 MySQL 服务。

于 2013-09-14T09:49:00.363 回答