如何使包装器返回除引用光标之外的其他内容

发布于 2024-10-11 09:34:45 字数 1847 浏览 1 评论 0原文

我有以下 PL SQL 函数,它返回引用游标,但我正在使用的应用程序不支持引用游标。我怎样才能让这段代码返回除引用光标

FUNCTION getADedIcWarningsProv(p_hos_id IN work_entity_data.hos_id%TYPE
                                ,p_date        IN DATE
                                )


RETURN eOdatatypes_package.eOrefcur
  IS

v_refcur eOdatatypes_package.eOrefcur;

BEGIN

OPEN v_refcur FOR
SELECT IF_type IF_type
      ,COUNT(*)       number_infected
FROM (SELECT DISTINCT bd.PT_id             PT_id
                     ,CASE WHEN NVL(O_package.get_O_code_property(pw.warning_code,'Setl'),'N') = 'Y'
                      THEN cd.description
                      ELSE 'Other'
                      END                       IF_type
      FROM PT_ad       pad
          ,BD_details      bd
          ,PT_warnings pw
          ,codes            cd
      WHERE bd.current_record = 'Y'
      AND   bd.BD_location IS NOT NULL
      AND   bd.BD_status IN (SELECT code
                                FROM codes
                               WHERE prog_code IN (1, 1, 2) 
                                 AND code_type = 4)
      AND   bd.AD_no = pad.AD_no
      AND   pad.hos_id = p_hos_id
      AND   pw.PT_id   = bd.PT_id
      AND   pw.warning_to IN ('D','Q')
      AND   p_date BETWEEN pw.applies_start
                       AND NVL(pw.applies_end,p_date)
      AND   NVL(O_package.get_O_code_property(pw.warning_code,'INFT'),'Y') = 'N'
      AND   pw.warning_code = cd.code)
GROUP BY IF_type
ORDER BY IF_type;
RETURN v_refcur;
END getADedIcWarningsProv;

输出之外的其他内容:

IF_TYPE                           NUMBER_IF
---------------------------------------- ---------------
C                                                 2
M                                                 6
Other                                             4
3 rows selected

I've got the following PL SQL function that returns a ref cursor but the application i am using does not support ref cursors. How can i make this code return something other than ref cursor

FUNCTION getADedIcWarningsProv(p_hos_id IN work_entity_data.hos_id%TYPE
                                ,p_date        IN DATE
                                )


RETURN eOdatatypes_package.eOrefcur
  IS

v_refcur eOdatatypes_package.eOrefcur;

BEGIN

OPEN v_refcur FOR
SELECT IF_type IF_type
      ,COUNT(*)       number_infected
FROM (SELECT DISTINCT bd.PT_id             PT_id
                     ,CASE WHEN NVL(O_package.get_O_code_property(pw.warning_code,'Setl'),'N') = 'Y'
                      THEN cd.description
                      ELSE 'Other'
                      END                       IF_type
      FROM PT_ad       pad
          ,BD_details      bd
          ,PT_warnings pw
          ,codes            cd
      WHERE bd.current_record = 'Y'
      AND   bd.BD_location IS NOT NULL
      AND   bd.BD_status IN (SELECT code
                                FROM codes
                               WHERE prog_code IN (1, 1, 2) 
                                 AND code_type = 4)
      AND   bd.AD_no = pad.AD_no
      AND   pad.hos_id = p_hos_id
      AND   pw.PT_id   = bd.PT_id
      AND   pw.warning_to IN ('D','Q')
      AND   p_date BETWEEN pw.applies_start
                       AND NVL(pw.applies_end,p_date)
      AND   NVL(O_package.get_O_code_property(pw.warning_code,'INFT'),'Y') = 'N'
      AND   pw.warning_code = cd.code)
GROUP BY IF_type
ORDER BY IF_type;
RETURN v_refcur;
END getADedIcWarningsProv;

OUTPUT:

IF_TYPE                           NUMBER_IF
---------------------------------------- ---------------
C                                                 2
M                                                 6
Other                                             4
3 rows selected

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤君无依 2024-10-18 09:34:45

您可以使用管道函数以 SQL 引擎可以理解的方式一次返回一条记录的结果集。

create or replace package WrapperSample is

  type TResultRow is record(
     if_type         codes.cd%type
    ,number_infected Integer);

  type TResultRowList is table of TResultRow;

  function GetADedIcWarningsProv
  (
    p_hos_id in work_entity_data.hos_id%type
   ,p_date   in date
  ) return TResultRowList
    pipelined;

end WrapperSample;
/

create or replace package body WrapperSample is

  function GetADedIcWarningsProv
  (
    p_hos_id in work_entity_data.hos_id%type
   ,p_date   in date
  ) return TResultRowList
    pipelined is
    v_refcur   eOdatatypes_package.eOrefcur;
    currentRow TResultRow;
  begin
    v_refcur := YourSchema.getADedIcWarningsProv(p_hos_id, p_date);

    loop
      fetch v_refcur
        INTO currentRow;
      exit when v_refcur%NotFound;
      pipe row(currentRow);
    end loop;

    close v_refcur;

    return;
  end;

end WrapperSample;
/

使用这个包,您可以选择参考光标:

SELECT if_type
      ,number_infected
FROM table(WrapperSample.getADedIcWarningsProv(1, 2))

You can use a pipeline function to return a result set one record at a time, but in a way that the SQL engine can understand.

create or replace package WrapperSample is

  type TResultRow is record(
     if_type         codes.cd%type
    ,number_infected Integer);

  type TResultRowList is table of TResultRow;

  function GetADedIcWarningsProv
  (
    p_hos_id in work_entity_data.hos_id%type
   ,p_date   in date
  ) return TResultRowList
    pipelined;

end WrapperSample;
/

create or replace package body WrapperSample is

  function GetADedIcWarningsProv
  (
    p_hos_id in work_entity_data.hos_id%type
   ,p_date   in date
  ) return TResultRowList
    pipelined is
    v_refcur   eOdatatypes_package.eOrefcur;
    currentRow TResultRow;
  begin
    v_refcur := YourSchema.getADedIcWarningsProv(p_hos_id, p_date);

    loop
      fetch v_refcur
        INTO currentRow;
      exit when v_refcur%NotFound;
      pipe row(currentRow);
    end loop;

    close v_refcur;

    return;
  end;

end WrapperSample;
/

Using this package, you can select your ref cursor:

SELECT if_type
      ,number_infected
FROM table(WrapperSample.getADedIcWarningsProv(1, 2))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文