2

在我的包中,我定义了一个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;
/
4

1 回答 1

4
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;
于 2012-08-21T12:21:58.827 回答