0

我正在尝试运行以下函数,但收到错误“$1 处或附近的语法错误”有人可以帮我解决这个问题吗?谢谢!

CREATE OR REPLACE FUNCTION vin_calc() RETURNS text AS
$BODY$
DECLARE
    r res%rowtype;
    i integer default 0;
    x  text;
    curs2 CURSOR FOR SELECT * FROM res;
BEGIN
    FOR r IN curs2 

    LOOP
    if(x!=r.prod_grp_nm)
    i=0 
    end

     i:=i+1;

     if (i=1)
      update res set duration =0 where CURRENT OF curs2;

     elsif(i=2)
     update res set duration =1 where CURRENT OF curs2;

     elsif(i>=3)
     update res set gwma_duration =0.75*lag(res.duration,1)+(0.125*r.dur) where CURRENT OF curs2;
     end    

    x:=r.prod_grp_nm;      

    END LOOP;
    RETURN 'yes';
END
$BODY$
LANGUAGE 'plpgsql' ;
4

0 回答 0