Nik*_*ike 3 postgresql variables declare
我想在postgres中声明变量但不在函数中...
Declare
c varchar;
a integer;
b integer;
select b = count (*) from table
set a = 1
while a <= b
begin
select c = [c] from table where id = a
if (c = '1')
insert into table2 select(*) from table
end
set a = a+1
Run Code Online (Sandbox Code Playgroud)
但错误错误:"varchar"或附近的语法错误第2行:c varchar; 我希望任何人都可以帮助我
a_h*_*ame 10
如果您使用的是9.0,则可以使用DO语句使用匿名块:
http://www.postgresql.org/docs/current/static/sql-do.html
在9.0之前,您无法使用匿名的pl/pgSQL块,您需要为此创建一个函数.
另外,你有完全错误的pl/pgSQL语法.
您不能在同一行中具有赋值和WHILE语句.您还缺少WHILE循环的其他requird关键字.
请参阅手册以了解正确的语法:
http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#AEN50163
从select到变量读取值的语法也是错误的.
检索SELECT结果的正确语法是:
SELECT count(*)
INTO b
FROM some_table;
Run Code Online (Sandbox Code Playgroud)
查看手册也是如此:
http://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW
| 归档时间: |
|
| 查看次数: |
9222 次 |
| 最近记录: |