1
我需要從Oracle過程返回一個遊標,遊標必須包含RECORD類型。當RECORD很簡單時,我知道如何解決這個問題,但是如何解決這個問題?NESTED RECORDS?如何從Oracle過程返回填充了NESTED RECORD類型的遊標
目前的代碼簡單的記錄工作塊:
-- create package with a RECORD type
create or replace package pkg as
-- a record contains only one simple attribute
type t_rec is RECORD (
simple_attr number
);
end;
/
-- create a testing procedure
-- it returns a cursor populated with pkg.t_rec records
create or replace procedure test_it(ret OUT SYS_REFCURSOR) is
type cur_t is ref cursor return pkg.t_rec;
cur cur_t;
begin
-- this is critical; it is easy to populate simple RECORD type,
-- because select result is mapped transparently to the RECORD elements
open cur for select 1 from dual;
ret := cur; -- assign the cursor to the OUT parameter
end;
/
-- and now test it
-- it will print one number (1) to the output
declare
refcur SYS_REFCURSOR;
r pkg.t_rec;
begin
-- call a procedure to initialize cursor
test_it(refcur);
-- print out cursor elements
loop
fetch refcur into r;
exit when refcur%notfound;
dbms_output.put_line(r.simple_attr);
end loop;
close refcur;
end;
/
你能告訴我,如何當一個記錄t_rec包含嵌套RECORD它可以做?
修改示例如下因素的方法:
-- create package with a NESTED RECORD type
create or replace package pkg as
type t_rec_nested is RECORD (
nested_attr number
);
-- a record with NESTED RECORD
type t_rec is RECORD (
simple_attr number,
nested_rec t_rec_nested
);
end;
/
create or replace procedure test_it(ret OUT SYS_REFCURSOR) is
type cur_t is ref cursor return pkg.t_rec;
cur cur_t;
begin
-- how to populate a result?
open cur for ????
ret := cur;
end;
/
的問題是如何修改test_it過程來填充光標? 我花了很多時間搜索解決方案,我會感謝任何幫助。
是的!我不明白我怎麼能錯過這樣一個明顯的解決方案。非常感謝你。 – giorge 2012-01-17 13:54:50