如何在存储过程中存储来自查询的多个变量?
对于一个变量,它可以很容易地完成,但是如果对于同一个查询有多个变量,该怎么办呢?
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;
有没有不使用游标变量
的简单方法?
最佳答案
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/