PostgreSQL - 分配变量时出现语法错误?
PostgreSQL - Syntax error while assigning variable?
这是我的代码:
amount INTEGER;
amount := select count(*) from moneyTable;
我收到以下错误:
ERROR: syntax error at or near "select"
谁能帮帮我。
来自fine manual:
An assignment of a value to a PL/pgSQL variable is written as:
variable { := | = } expression;
但 select ...
不是表达式。如果要将 SELECT 中的值分配给变量,则需要使用 INTO:
select count(*) into amount from moneyTable;
-- ^^^^^^^^^^^
答案或这个
amount := (select count(*) from moneyTable);
这是我的代码:
amount INTEGER;
amount := select count(*) from moneyTable;
我收到以下错误:
ERROR: syntax error at or near "select"
谁能帮帮我。
来自fine manual:
An assignment of a value to a PL/pgSQL variable is written as:
variable { := | = } expression;
但 select ...
不是表达式。如果要将 SELECT 中的值分配给变量,则需要使用 INTO:
select count(*) into amount from moneyTable;
-- ^^^^^^^^^^^
amount := (select count(*) from moneyTable);