【问题标题】:Casting Oracle cursor row into user-defined record type for a pipelined function将 Oracle 游标行转换为流水线函数的用户定义记录类型
【发布时间】:2012-08-21 12:08:21
【问题描述】:

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

【问题讨论】:

    标签: oracle types casting plsql cursor


    【解决方案1】:
    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;
    

    【讨论】:

    • 谢谢,勒内。另外,当您在这里时,还要感谢您的网站:它是我的永久参考,并教会了我很多 Oracle 课程:)
    猜你喜欢
    • 1970-01-01
    • 2012-02-08
    • 2013-11-27
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    • 2011-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多