两个游标嵌套使用出错
大家好:
怎么在程序体内使用游标,红色标记的那个位置不能声明游标,怎么解决?或者怎么样优化此存储过程实现我想要的功能,
解决马上结帐,谢谢
create procedure testsql(out osql varchar(8000))
language sql
begin
declare defaultsql varchar(8000);
declare sql varchar(8000);
declare v_formulaid int;
declare v_itemname varchar(50);
declare v_formula varchar(100);
declare v_count int;
declare v_countitem int;
declare c1 cursor for
select formulaid from salaryformula order by formulaid;
select count(1) into v_count from salaryformula;
open c1;
while v_count>0 do
set defaultsql='update tblpaylistsheetitem set ';
fetch c1 into v_formulaid;
declare c1item cursor for select itemname,formula from salaryformulaitem where formulaid= v_formulaid order by formulaindex;
select count(1) into v_countitem from salaryformulaitem where formulaid= v_formulaid;
open c1item;
while v_countitem>0 do
fetch c1item into v_itemname,v_formula;
set defaultsql=defaultsql || replace(replace((',' || v_itemname || ' = ' || v_formula),'[',''),']','');
set v_countitem=v_countitem-1;
end while;
close c1item;
set sql=sql+defaultsql +' where salarytype='' || v_formulaid || '';';
set v_count=v_count-1;
end while;
close c1;
set osql=sql;
end@