可以先转 array 再转 string 给你看个DEMO
do
$$
declare
recs record;
begin
drop table if exists test;
create temporary table test(
col1 varchar,
col2 varchar,
value integer
);
insert into test values('11' , '22' , 11);
insert into test values('22' , '33' , 22);
insert into test values('33' , '44' , 33);
-- sql : select array_to_string(array_agg(col1 || '-' || col2 || ' - ' || value)) from test
for recs in select array_to_string(array_agg(col1 || '-' || col2 || ' 利率: ' || value) , ';') || ';' as t from test loop
raise notice ' text :%' , recs.t;
end loop;
end;
$$