gpt4 book ai didi

oracle - 将 Oracle 游标行转换为流水线函数的用户定义记录类型

转载 作者:行者123 更新时间:2023-12-04 18:14:09 25 4
gpt4 key购买 nike

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

关于oracle - 将 Oracle 游标行转换为流水线函数的用户定义记录类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12054505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com