存储变量

时间:2012-03-22 05:13:14

标签: postgresql

postgresql中是否有任何方法可以将特定列的值存储到变量中。

例如

name   | age
       |
John   | 19
Phill  | 20
Palmer | 25

我想将25存储到我将来可以参考的变量中。

1 个答案:

答案 0 :(得分:1)

不确定。使用存储过程。 http://www.postgresql.org/docs/current/static/plpgsql.html 琐碎的例子:

CREATE OR REPLACE FUNCTION JohnName()
      RETURNS numeric AS
    $BODY$
      DECLARE num numeric;
      BEGIN
        select age into num from yourtable where name = 'John';
        num := num * 2;
        RETURN num;
      END
    $BODY$
      LANGUAGE plpgsql VOLATILE;

      select * from JohnName()