【问题标题】:Procedure with OUT parameters in a PostgreSQL package not workingPostgreSQL 包中带有 OUT 参数的过程不起作用
【发布时间】:2016-07-29 07:14:28
【问题描述】:

在从 Oracle 迁移到 PostgreSQL 期间。我遇到一个问题: PostgreSQL 包中带有 OUT 参数的过程不起作用。每当运行程序时,它都会说程序不存在

CREATE OR REPLACE PACKAGE pkg_productdetails
IS
  Procedure p_getprod_details(in_locationid numeric, OUT cur_Product_typedetails refcursor, OUT cur_Productlist refcursor);
END pkg_productdetails;

CREATE OR REPLACE PACKAGE BODY pkg_productdetails
IS
  Procedure p_getprod_details(in_locationid numeric, OUT cur_Product_typedetails refcursor, OUT cur_Productlist refcursor) IS
  BEGIN
      OPEN cur_Product_typedetails FOR
--select the cur_Product_typedetails ;

 OPEN cur_Productlist FOR
--select the cur_Productlist;

  END;
END pkg_productdetails;

当我运行这个程序时,它说 pkg_productdetails.p_getprod_details(numeric) 不存在

SELECT pkg_productdetails.p_getprod_details(10001);

【问题讨论】:

  • @a_horse_with_no_name 是的,我正在使用 EnterpriseDB
  • 你调用了一个只有3个参数的过程,其中一个和两个是OUT?你需要两个游标变量来发送到这个过程。
  • @Motor 当我们使用所有 3 个参数(1 IN 和 2 OUT)从代码中调用此 pacakge.procedure 时。它给出了同样的错误。
  • 当出现“程序不存在”时,有两种情况,您看不到程序,因为您没有授权/同义词等,或者您有另一个签名(顺序和类型参数)。显示你怎么称呼它,因为上面的这个 EXEC 是不对的。
  • @Motor 这是我们在 Package.procedure 中使用 OUT 参数时的示例。同一包 pkg_productdetails 中没有 OUT 参数的其他程序运行良好。这不是代码问题,因为所有其他函数、过程和 package.procedures 都可以正常工作,但包中带有 OUT 参数的过程除外。我们将所有参数发送到 package.procedure。

标签: postgresql stored-procedures enterprisedb


【解决方案1】:

我必须解决这种情况 如果我们将过程转换为函数,它就可以工作了。

CREATE OR REPLACE PACKAGE pkg_productdetails
IS
  Function p_getprod_details(in_locationid numeric) RETURNS SETOF refcursor;
END pkg_productdetails;

CREATE OR REPLACE PACKAGE BODY pkg_productdetails
IS
  FUNCTION p_getprod_details(in_locationid numeric) RETURNS SETOF refcursor IS
cur_Product_typedetails refcursor;
cur_Productlist  refcursor;

  BEGIN
  OPEN cur_Product_typedetails FOR
--select the cur_Product_typedetails ;
return next cur_Product_typedetails;


 OPEN cur_Productlist FOR
--select the cur_Productlist;
return next cur_Productlist;

  END;
END pkg_productdetails;

当我运行这个包函数时,它正在工作 pkg_productdetails.p_getprod_details(numeric)。

SELECT pkg_productdetails.p_getprod_details(10001);

返回<unnamed portal 1><unnamed portal 2>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-11
    • 2013-11-02
    • 1970-01-01
    • 2015-12-06
    • 2013-01-08
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    相关资源
    最近更新 更多