PG将多个记录值通过into设置给一个变量的时候,此时变量会取第一个值,不会报错
程序员文章站
2022-05-10 10:48:43
...
直接看例子
drop table if exists test;
create table test(id int, name varchar);
insert into test select n, n||'name' from generate_series(1,10) as t(n);
CREATE OR REPLACE FUNCTION func_test()
RETURNS INTEGER
AS
$BODY$
DECLARE
tmp_name varchar;
BEGIN
select name into tmp_name from test where id<10;
raise notice 'tmp_name = %', tmp_name;
RETURN 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
select * from func_test()
- 结果: