gpt4 book ai didi

sql - PostgreSQL,在存储过程中存储多个变量

转载 作者:行者123 更新时间:2023-11-29 12:37:25 25 4
gpt4 key购买 nike

如何在存储过程中存储来自查询的多个变量?

对于一个变量,它可以很容易地完成,但是如果对于同一个查询有多个变量,该怎么办呢?

declare num1 int;
declare num2 int;
select number1 into num1 from table_a where id = 1;

-- This one is not correct
select number1 into num1, number2 into num2 from table_a where id = 1;

有没有不使用游标变量的简单方法?

最佳答案

Quote from the manual:

where target can be a record variable, a row variable, or a comma-separated list of simple variables

所以应该是:

select number1, number2 
into num1, num2
from table_a where id = 1;

或者,您可以使用记录变量:

declare result_rec record;
...

select number1, number2
into result_rec
from table_a where id = 1;

关于sql - PostgreSQL,在存储过程中存储多个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26548721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com