如何从PostgreSQL函数中的select中设置值?

时间:2016-10-06 19:46:32

标签: postgresql plpgsql

我在PostgreSQL函数(plpgsql)中声明了一些变量,我想从select table中设置一个值。我怎么能正确地做到这一点?

这样的功能:

DECLARE
 a NUMERIC(18,6);
 b int;
 c int;
 d NUMERIC(18,6);
 e int;
 f boolean;
BEGIN

SELECT  a = "st"."cl1",
              b = "st"."cl2",
              c = "st"."cl3",
              d = "st"."cl4",
              e ="st"."cl5",
              f ="st"."cl6"

FROM "test"."table" st limit 1;

1 个答案:

答案 0 :(得分:1)

select
    "st"."cl1", "st"."cl2", "st"."cl3", "st"."cl4", "st"."cl5", "st"."cl6"
    into
    a, b, c, d, e, f
from "test"."table" st
limit 1;