--这里去创建一个function name为redpacket_data 里面包含三个变量 第一个为char类型 后面两个为bigint类型,下面的function中变量a1并没有用到,只是为了区分变量类型
--for ii in .. loop end loop 为循环
create or replace function redpacket_data(a1 char(10), a2 bigint, a3 bigint) returns
void as $$
declare ii integer;
begin
II:=1;
FOR ii IN a2..a3 LOOP
INSERT INTO public.driver_redpacket
(id, redpacket_unique_id)
VALUES(nextval('seq_driver_redpacket'), ''SSSS'||to_char(ii,'99999'));
end loop;
end;
$$ language plpgsql;
select redpacket2('redpacket_unique_id',1, 1000)
create or replace function redpacket2(a1 char(10), a2 bigint) returns
void as $$
declare ii integer;
begin
II:=1;
FOR ii IN 1..a3 LOOP
INSERT INTO public.driver_redpacket
(id, redpacket_unique_id)
VALUES(nextval('seq_driver_redpacket'), ''SSSS'||to_char(ii,'99999'));
end loop;
end;
$$ language plpgsql;
select redpacket2('redpacket_unique_id',1000)