ccodes.net
专注资源分享

postgresql 循环函数的简单实现操作

 

这篇文章主要介绍了postgresql 循环函数的简单实现操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧。我就废话不多说了,大家还是直接看代码吧~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 plpgsql;
 
select aa1(array[1,4,5,6,7,8],6742) 补充:数据库之postgreSql库的存储过程和循环总结postgreSql库中存储过程模板CREATE OR REPLACE FUNCTION p_fx_*** ( OUT v_row INTEGER, OUT v_rote varchar(50), OUT v_log varchar(50))
AS $$
DECLARE
BEGIN
 
 select count(*) into v_row from *插入表的名字*;
 v_rote := ‘SUCCESS’;
 v_log := ‘SUCCESS’;
 
END
$$
LANGUAGE plpgsql VOLATILE postgreSql库中循环书写的模板,以实际开发中的sql为例单层循环do $$
declare ***:=***;
begin
  while *** loop
  end loop;
end $$; declare –声明变量,如果声明了变量别忘了加分号;双层循环do $$
declare ***:=***;
begin
  while *循环条件* loop
    for i in 1..12 loop
    raise notice ‘%’,*变量名*;
    end loop;
  end loop;
end $$; 将循环放到存储过程中CREATE OR REPLACE FUNCTION p_fx_*** ( OUT v_row INTEGER, OUT v_rote varchar(50), OUT v_log varchar(50))
AS $$
DECLARE
BEGIN
 
while *循环条件* loop
    for i in 1..12 loop
    raise notice ‘%’,*变量名*;
    end loop;
  end loop;
 
 select count(*) into v_row from *插入表的名字*;
 v_rote := ‘SUCCESS’;
 v_log := ‘SUCCESS’;
END
$$
LANGUAGE plpgsql VOLATILE文章

'); })();