BEGIN
DECLARE company_code_val VARCHAR(16);
declare done int DEFAULT 0;
DECLARE count int DEFAULT 0;
DECLARE companyid_cursor CURSOR for SELECT companycode from bis_company;
declare continue handler FOR NOT FOUND SET done = 1;
OPEN companyid_cursor;
while done <>1 do
FETCH companyid_cursor into company_code_val;
set count=count+1;
IF company_code_val=@noid THEN
insert into test_cj(a)values('aaaa');
ELSE
insert into test_cj(b)values(company_code_val);
end if;
end while;
CLOSE companyid_cursor;
select count;
end
游标数据只有20条但是count的输出结果是21
DECLARE company_code_val VARCHAR(16);
declare done int DEFAULT 0;
DECLARE count int DEFAULT 0;
DECLARE companyid_cursor CURSOR for SELECT companycode from bis_company;
declare continue handler FOR NOT FOUND SET done = 1;
OPEN companyid_cursor;
while done <>1 do
FETCH companyid_cursor into company_code_val;
set count=count+1;
IF company_code_val=@noid THEN
insert into test_cj(a)values('aaaa');
ELSE
insert into test_cj(b)values(company_code_val);
end if;
end while;
CLOSE companyid_cursor;
select count;
end
游标数据只有20条但是count的输出结果是21