表2有结构 v_1,v_2,v_3
每次我只想选择一个变量,所以想在存储过程中引用循环索引i。这可能在TD吗?
++++++++++++++++++++++
replace procedure abc();
begin;
declare i integer default 0;
loopi: loop
set i = i + 1;
if i > 10 then leave loopi;
end if;
insert into table1
select * from table2
where v_i = 1;
end loop loopi;
end;
答案 0 :(得分:0)
当你在REPLACE和BEGIN之后删除分号时,这应该按原样运行:
replace procedure abc()
begin
declare i integer default 0;
loopi: loop
set i = i + 1;
if i > 10 then leave loopi;
end if;
insert into table1
select * from table2
where v_i = 1;
end loop loopi;
end;