gpt4 book ai didi

mysql - 声明在此位置无效,期望

转载 作者:行者123 更新时间:2023-11-29 15:57:23 25 4
gpt4 key购买 nike

声明了哪些出现了前所未见的错误,并试图找到解决方案。与以前的程序一样奇怪,它使用相同的语法但不会抛出任何错误

这是一个使用游标从表中检索信息,然后将其插入到另一个表中的过程,这样做是为了可以使用其中的信息来计算总计,该总计与一些信息一起传递所需值

BEGIN
DECLARE fin INT DEFAULT FALSE;
DECLARE pol VARCHAR(30) default '';
DECLARE total_accrued decimal(20,2) DEFAULT '0.00';
DECLARE total_paid decimal(20,2) DEFAULT '0';
DECLARE TOTAL DECIMAL(20,2) DEFAULT '0.00';
DECLARE user_pol varchar(45) default '';

DECLARE c3 CURSOr FOR SELECT total_accrued FROM fn_policy_mast;
DECLARE c4 CURSOR FOr SELECT total_amount_paid FROM fn_policy_mast;
DECLARE c2 CURSOR FOR SELECt policy_number FROM fn_policy_mast;
DECLARE c1 CURSOr FOR SELECT balance FROM fn_policy_mast;

-- DECLARE d_policy CURSOR FOR SELECT DISTINCT cod_policy FROM fn_policy_mast;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET fin = TRUE;

OPEN c1;
OPEN c2;
OPEN c3;
OPEN c4;
-- OPEN d_policy;

read_loop: LOOP

FETCH c3 INTO total_accrued;
FETCH c4 INTO total_paid;
FETCH c2 INTO pol;
set total = 0;
-- FETCH d_policy INTO user_pol;

-- IF user_pol = pol then
set total_accrued = (SELECT SUM(monthly_premium) FROM col_trans_log WHERE policy_number LIKE pol);
set total_paid = (SELECT SUM(transaction_amount) FROM col_Trans_log WHERE policy_number LIKE pol);

set total = total_paid - total_accrued;
-- END IF;

-- set TOTAL = (total_accrued-total_paid);
UPDATE fn_policy_mast set balance = TOTAL WHERE policy_number like pol;


IF fin=TRUE THEN
LEAVE read_loop;
END IF;


-- INSERT STATEMENTS HERE
-- set total = 0;
END LOOP;
select * FROM fn_policy_mast;
close c1;
close c2;
CLOSE c3;
CLOSE c4;

END//
DELIMITER ;````

Expected result to run, accepting the declares, actual experience is thaere is some form of syntax wrong, as it does not properly recognise the declare statements

This is the error message : 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 '' at line 5

最佳答案

DECLARE total_paid decimal(20,2) DEFAULT '0'

这是线吗?您是否尝试过将默认值更改为“0.00”?

关于mysql - 声明在此位置无效,期望,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56375336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com