yql0127 2015-08-14 09:37 采纳率: 100%
浏览 5446
已采纳

错误代码: 1064 You have an error in your SQL syntax;

求高手指点 语法哪里有问题啊

DELIMITER $$

CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE x_similarity.CovarianceEngine()
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN
/* 定义变量一 /
DECLARE done, done2 INT DEFAULT 0;
DECLARE stockNo_a VARCHAR(6);
DECLARE coefficient DOUBLE(16,14);
/
定义光标 */

DECLARE _Cur CURSOR FOR

SELECT DISTINCT stock_no FROM history_day;

DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;#错误定义,标记循环结束  

/* 打开光标 */  
OPEN _Cur;  
     /* 循环执行 */  
    REPEAT  
        FETCH _Cur INTO stockNo_a;  
        IF NOT done THEN  
            BEGIN
                /* 定义变量一 */  
                DECLARE stockNo_b VARCHAR(6);
                /* 定义光标 */ 
                DECLARE _CurInner CURSOR FOR  
                    SELECT DISTINCT stock_no FROM history_day;
                OPEN _CurInner;
                    REPEAT
                    FETCH _CurInner INTO stockNo_b;
                      IF NOT done2 THEN

                        SELECT
                            (
                                AVG(a. CLOSE * b. CLOSE) - AVG(a. CLOSE) * AVG(b. CLOSE)
                            ) / SQRT(
                                (
                                    AVG(a. CLOSE * a. CLOSE) - AVG(a. CLOSE) * AVG(a. CLOSE)
                                ) * (
                                    AVG(b. CLOSE * b. CLOSE) - AVG(b. CLOSE) * AVG(b. CLOSE)
                                )
                            ) INTO coefficient
                        FROM
                            history_day a,
                            history_day b
                        WHERE
                            a.date = b.date
                        AND a.date >= '2015-08-05'
                        AND a.date <= '2015-08-11'
                        AND a.stock_no = stockNo_a
                        AND b.stock_no = stockNo_b;

                        IF coefficient > 0.5 OR coefficient < -0.5 THEN

                            INSERT INTO correlationanalysis (stock_no_f, stock_no_r, coefficient) VALUES(stockNo_a, stockNo_b, coefficient);
                            COMMIT;

                        END IF;

                      END IF;
                    UNTIL done2 END REPEAT;
                    CLOSE _CurInner;
                SET done2 = 0;
            END
        END IF;
    UNTIL done END REPEAT;
CLOSE _Cur;
END$$

DELIMITER ;

错误代码: 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 'END IF;
UNTIL done END REPEAT;
CLOSE _Cur;
END' at line 65

  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。