我找不到错误。你能救我吗?
DELIMITER $$
CREATE PROCEDURE ReadBalance (IN mes INT,IN anio INT)
BEGIN
DECLARE rowid INT;
DECLARE entity INT;
DECLARE grupo VARCHAR(100);
DECLARE relacion INT;
DECLARE ini INT;
DECLARE fin INT;
DECLARE tipo INT;
DECLARE detalle INT;
DECLARE ctain INT;
DECLARE ctaen INT;
DECLARE debe DECIMAL(17,2);
DECLARE haber DECIMAL(17,2);
DECLARE saldo DECIMAL(17,2);
DECLARE done INT DEFAULT 0;
CREATE TEMPORARY TABLE Balance (
rowid INT NOT NULL
, entity TINYINT NOT NULL DEFAULT 0
, grupo VARCHAR(150) NOT NULL
, relacion INT UNSIGNED NOT NULL DEFAULT 0
, ini INT UNSIGNED NOT NULL DEFAULT 0
, fin INT UNSIGNED NOT NULL DEFAULT 0
, tipo INT UNSIGNED NOT NULL DEFAULT 1
, detalle INT UNSIGNED NOT NULL DEFAULT 0
, ctain INT UNSIGNED NOT NULL DEFAULT 0
, ctaen INT UNSIGNED NOT NULL DEFAULT 0
, debe DECIMAL(12,2) NOT NULL DEFAULT 0.00
, haber DECIMAL(12,2) NOT NULL DEFAULT 0.00
, saldo DECIMAL(12,2) NOT NULL DEFAULT 0.00
) ENGINE=MEMORY;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
DECLARE cur1 CURSOR FOR
SELECT
g.`rowid`,
g.`entity`,
g.`grupo`,
g.`fk_codagr_rel`,
g.`fk_codagr_ini`,
g.`fk_codagr_fin`,
g.`tipo_edo_financiero`,
g.`Detalle`,
ctai.`cta`,
ctae.`cta`
FROM
`llx_contab_grupos` g
INNER JOIN `llx_contab_cat_ctas` ctai
ON ctai.`rowid` = g.`fk_codagr_ini`
INNER JOIN llx_contab_cat_ctas ctae
ON ctae.`rowid` = g.`fk_codagr_fin` ;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO rowid, entity, grupo,relacion, ini,fin,tipo,detalle,ctain,ctaen;
IF done =1THEN
LEAVE read_loop;
END IF;
SELECT debe := SUM(d.`debe`), haber:= SUM(d.`haber`) FROM `llx_contab_polizasdet` d
INNER JOIN llx_contab_polizas e ON e.`rowid` = d.`fk_poliza`
WHERE e.`anio` = anio
AND e.`mes` = mes
AND d.`cuenta` >= ctain
AND d.`cuenta` <= ctaen
;
saldo = debe-haber;
INSERT INTO Balance (
rowid,
entity,
grupo,
relacion,
ini,
fin,
tipo,
detalle,
ctain,
ctaen,
debe,
haber,
saldo
)
VALUES
(
rowid,
entity,
grupo,
relacion,
ini,
fin,
tipo,
detalle,
ctain,
ctaen,
debe,
haber,
saldo
) ;
END LOOP read_loop;
CLOSE cur1;
SELECT * FROM Balance;
END$$
DELIMITER ;
错误消息:
执行了1个查询,0个成功,1个错误,0个警告
查询:
CREATE PROCEDURE ReadBalance (IN mes INT,IN anio INT) BEGIN DECLARE rowid INT;
DECLARE entity INT;
DECLARE grupo VARCHAR(100); D...
错误代码:1064您的SQL语法出错;检查 手册,对应右边的MySQL服务器版本 在'DECLARE CONTINUE HANDLER附近使用的语法for NOT FOUND SET done = 1;
DECLARE cur1 CURSOR FOR
SE' at line 32
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0 sec
答案 0 :(得分:0)
我创建了这个,并且正常工作;
DELIMITER $$
USE `tindustrial`$$
DROP PROCEDURE IF EXISTS `Cur`$$
CREATE DEFINER = `root` @`localhost` PROCEDURE `Cur` ()
BEGIN
DECLARE rowid INT ;
DECLARE entity INT ;
DECLARE grupo VARCHAR (100) ;
DECLARE relacion INT ;
DECLARE ini INT ;
DECLARE fin INT ;
DECLARE tipo INT ;
DECLARE detalle INT ;
DECLARE ctain INT ;
DECLARE ctaen INT ;
DECLARE debe DECIMAL (17, 2) ;
DECLARE haber DECIMAL (17, 2) ;
DECLARE saldo DECIMAL (17, 2) ;
DECLARE no_more_rows BOOLEAN ;
DECLARE cur_B CURSOR FOR
SELECT
g.rowid,
g.entity,
g.grupo,
g.fk_codagr_rel,
g.fk_codagr_ini,
g.fk_codagr_fin,
g.tipo_edo_financiero,
g.Detalle,
ctai.cta,
ctae.cta
FROM
llx_contab_grupos g
INNER JOIN llx_contab_cat_ctas ctai
ON ctai.rowid = g.fk_codagr_ini
INNER JOIN llx_contab_cat_ctas ctae
ON ctae.rowid = g.fk_codagr_fin ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_rows = 1 ;
CREATE TEMPORARY TABLE Balance (
rowid INT NOT NULL,
entity TINYINT NOT NULL DEFAULT 0,
grupo VARCHAR (150) NOT NULL,
relacion INT UNSIGNED NOT NULL DEFAULT 0,
ini INT UNSIGNED NOT NULL DEFAULT 0,
fin INT UNSIGNED NOT NULL DEFAULT 0,
tipo INT UNSIGNED NOT NULL DEFAULT 1,
detalle INT UNSIGNED NOT NULL DEFAULT 0,
ctain INT UNSIGNED NOT NULL DEFAULT 0,
ctaen INT UNSIGNED NOT NULL DEFAULT 0,
debe DECIMAL (12, 2) NOT NULL DEFAULT 0.0,
haber DECIMAL (12, 2) NOT NULL DEFAULT 0.0,
saldo DECIMAL (12, 2) NOT NULL DEFAULT 0.0
) ENGINE=MEMORY;
OPEN cur_b ;
the_loop :
LOOP
FETCH cur_B INTO rowid,
entity,
grupo,
relacion,
ini,
fin,
tipo,
detalle,
ctain,
ctaen ;
IF no_more_rows
THEN CLOSE cur_b ;
LEAVE the_loop ;
END IF ;
END LOOP the_loop ;
CLOSE cur_b ;
TRUNCATE TABLE Balance ;
END $$
DELIMITER ;