在同一个表中插入记录后,未在过程中完成更新

时间:2016-01-24 09:56:07

标签: mysql cursor

我在Cursor的帮助下将记录插入到表中并在关闭游标后循环我写了更新语句来更新一些由游标插入的记录,因此reords不更新。但我在外面运行查询然后记录更新

我的尝试是 drop procedure如果存在kpsf_inopdormantac;

create procedure kpsf_inopdormantac(inp_branchcode varchar(6), inp_date date)

begin  declare c_branchcode varchar(6);
declare c_accounttype varchar(4); 
declare c_accountsubtype varchar(6); 
declare c_accountno varchar(12);
declare c_lasttxndate date;
declare c_inopdate date;
declare c_temp varchar(25);

declare c1 cursor for SELECT
branchcode, accounttype, accountsubtype, accountno, lasttxndate, inoperativedate FROM accountmaster WHERE branchcode = inp_branchcode AND accounttype in ('10','11') AND accountstatus!='C' AND lasttxndate < ( SELECT date_add(inp_date,interval -24 month));

truncate table inopdormantac;
commit;
open c1;
loop1:loop fetch c1 into c_branchcode, c_accounttype, c_accountsubtype, c_accountno, c_lasttxndate, c_inopdate;

INSERT into inopdormantac (branchcode, accounttype, accountsubtype, accountno, acstatus, lasttxndate, inopdate)
VALUES 
(c_branchcode, c_accounttype, c_accountsubtype, c_accountno, 'InOperative', c_lasttxndate, c_inopdate);

end loop loop1;
close c1;
set c_temp='InActive';

update inopdormantac SET acstatus = c_temp WHERE lasttxndate < ( SELECT
date_add('2015-10-06',interval -120 month));
end;

请帮帮我

1 个答案:

答案 0 :(得分:0)

您可能正在以安全更新模式运行数据库实例。请查看已经回答的其他问题: MySQL error code: 1175 during UPDATE in MySQL Workbench