簡體   English   中英

將Oracle游標行強制轉換為用戶定義的記錄類型,以實現流水線函數

[英]Casting Oracle cursor row into user-defined record type for a pipelined function

在我的程序包中,我定義了一個record類型和一個對應的table類型。 然后,我有了一個流水線函數,該函數打開游標並嘗試通過管道傳遞每個結果。 問題是它給我類型不匹配錯誤。 我試圖將游標強制轉換為我的記錄類型,但無濟於事:我在做什么錯?

create or replace package myTest as
  type myRec is record(
    id  integer,
    foo varchar2(10)
  );
  type myTable is table of myRec;

  function output() return myTable pipelined;
end myTest;
/

create or replace package body myTest as
  function output() return myTable pipelined
  as
  begin
    for myCur in (
      select id, foo from someTable
    )
    loop
      pipe row(cast(myCur as myRec));
    end loop;

    return;
  end output;
end myTest;
/
create or replace package body myTest as
  function output return myTable pipelined
  as
    --   Add a "record" variable":
    xyz  myRec;
  begin
    for myCur in (
      select id, foo from someTable
    )
    loop
      -- Fill the record variable with the
      -- values from the cursor ...
      xyz.id  := myCur.id;
      xyz.foo := myCur.foo;
      -- ... and pipe it:
      pipe row(xyz);
    end loop;

    return;
  end output;
end myTest;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM