pl / sql:将游标类型转换为行对象

时间:2013-07-08 16:43:22

标签: oracle plsql

我有一个管道功能

row_t AS OBJECT(...);
table_t IS TABLE OF row_t
func_a RETURN table_t PIPELINED AS ...

另一个将row_t作为参数的函数:

func_b(row_in row_t)

现在,在一个过程中,我想将管道函数中的每一行传递给func_b

FOR c IN (SELECT * FROM TABLE(func_a()))
LOOP
    -- The following code gives compilation error,
    -- How do I convert c to row_t type???
    some_var := func_b(c);
    ...
END LOOP;

有什么建议吗?提前谢谢!

1 个答案:

答案 0 :(得分:1)

create or replace type row_t as object(a number, b number);

create or replace type table_t is table of row_t;

create or replace function func_a return table_t pipelined as
    v_row_t row_t := row_t(1, 2);
begin
    pipe row (v_row_t);
end;
/

create or replace function func_b(row_in row_t) return number as
begin
    return 3;
end;
/

declare
    v_row_t row_t;
    v_result number;
begin
    for c in
    (
        select * from table(func_a())
    ) loop
        v_result := func_b(row_t(c.a, c.b));
    end loop;
end;
/