如何在teradata SP中引用循环索引i?

时间:2013-09-24 06:40:50

标签: teradata

表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;

1 个答案:

答案 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;