如何在plpgsql中调用返回数据类型为void的函数a?
create or replace function f1() //procedure should display 9
returns void
as $$
declare age int default 9; //variable declaration
begin
select age; //prints 9
end;
$$ language plpgsql;
CREATE FUNCTION
我不断收到此错误
perform f1();
ERROR: syntax error at or near "perform"
LINE 1: perform f1();
create or replace function f1() //procedure should display 9
returns void
as $
declare age int default 9; //variable declaration
begin
select age; //prints 9
end;
$ language plpgsql;
CREATE FUNCTION
I keep receiving this error
perform f1();
ERROR: syntax error at or near "perform"
LINE 1: perform f1();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
perform
是一个 PL/pgSQL 语句。在普通 SQL 中,您只需使用 SELECT:请注意,编写的函数将不会“打印 9” - 它将导致错误,因为
SELECT
需要的结果存储在某个地方。在 PL/pgSQL 中,您需要 RAISE 语句来“打印”某些内容:如果您希望函数“显示”某些内容,那么让函数返回可能更有意义> 结果:
然后
select f1()
将“打印”9
perform
is a PL/pgSQL statement. In plain SQL, you simply use SELECT:Note that the function as written, will not "print 9" - it will result in an error as the result of a
SELECT
needs to be stored somewhere. In PL/pgSQL you would need theRAISE
statement to "print" something:If you want a function to "display" something, it might make more sense to let the function return a result:
Then
select f1()
will "print"9