FOR loop Netezza issue

夙愿已清 提交于 2019-12-11 13:55:25

问题


I'm working with stored procedures in netezza. I want to loop over a range of values. The upper bound on the loop is passed as a variable into the sproc by the user.

i.e. EXECUTE SPROC(12);

so problem is that Netezza (aginity workbench) won't accept this input variable as the upper bound on the loop.

i.e.

DECLARE 
 x alias as $1.
begin 
   for i in 1..x loop
     ...do stufff... 
    end loop; 
end;

I know that this can be solved using loop and exit style loop but It's eating me up as to why i can't do the above given that the documentation suggests that it's possible to do so.

Anyone know why this doesn't work or how to make it work?

Thanks. Clancy.


回答1:


Please find below working example -

CREATE OR REPLACE PROCEDURE generateTime(integer)
LANGUAGE NZPLSQL RETURNS varchar(255) AS

BEGIN_PROC

DECLARE
        p_abc     integer;
        p_bcd     integer;

        p_var1    ALIAS FOR $1;


BEGIN
        p_bcd := ISNULL(p_var1, 10);

        raise notice 'p_bcd=%',p_bcd;

        FOR p_abc in 0..(p_bcd)
        LOOP
                raise notice 'Hello World %', p_abc;
        END LOOP;
END;


END_PROC;

Hope this will help.



来源:https://stackoverflow.com/questions/21870410/for-loop-netezza-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!