postgresql 循环

CREATE or replace FUNCTION sde._loop_demo(IN st_time timestamp with time zone)
RETURNS integer
    LANGUAGE 'plpgsql'
AS $BODY$
declare
  p RECORD;
begin
raise info '%', st_time;
for p in
  SELECT
    public.water_protect_area_month_report.id,
    public.water_protect_area_month_report.water_source_code,
    public.water_protect_area_month_report.water_source_name
  FROM public.water_protect_area_month_report
  where
    public.water_protect_area_month_report.stat_time = st_time
    and public.water_protect_area_month_report.water_source_code <> ''
loop
  raise notice '% %', p.water_source_code, p.water_source_name;
end loop;
return 0;
end;
$BODY$;

猜你喜欢

转载自www.cnblogs.com/kerwincui/p/9122078.html