前端之家收集整理的这篇文章主要介绍了
postgresql实现简单的循环函数,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
404_0@create or replace function aa1(a1 integer[],a2 bigint) returns
void AS $$
declare ii integer;
declare num integer;
begin
II:=1;
num = 1;
FOR ii IN 1..a2 LOOP
UPDATE student SET
id=a1[num]
WHERE cd_id = ii;
num = num +1;
if (num>6) then
num = 1;
end if;
end loop;
end;
$$ LANGUAGE plpg
sql;
select aa1(array[1,4,5,6,7,8],6742)