【问题标题】:How to write stored procedure for select statment in postgersql如何在 postgresql 中为 select 语句编写存储过程
【发布时间】:2021-08-23 12:38:48
【问题描述】:

我想为下面的选择语句创建存储过程是我创建的过程,但它给数据输出空白

CREATE OR REPLACE PROCEDURE public.deactivate_unpaid_accounts()
    LANGUAGE 'sql'
    
AS $BODY$
select * from employees where salary=10000
$BODY$;

CALL deactivate_unpaid_accounts();

【问题讨论】:

  • Postgres 9.5 是 no longer supported(并且不支持存储过程)。您应该尽快计划升级。

标签: stored-procedures postgresql-9.5


【解决方案1】:

过程(从 9.5 开始不可用)不打算返回结果集。

如果要返回结果,应该使用 Postgres 中的函数。

CREATE OR REPLACE FUNCTION public.deactivate_unpaid_accounts() 
  returns setof employees
  LANGUAGE sql
AS $BODY$ 
  select * 
  from employees 
  where salary=10000;
 $BODY$;

然后像这样使用它:

select *
from deactivate_unpaid_accounts();

【讨论】:

    猜你喜欢
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    相关资源
    最近更新 更多