2012-01-16 3 views
1

カーソルをカーソルから戻す必要があります。カーソルにはRECORDタイプが含まれている必要があります。レコードがシンプルなときにこの問題を解決する方法はわかっていますが、どうすれば解決できるのですかネストレコードNESTED RECORDタイプを使用してカーソルをOracleプロシージャーから取り込む方法

シンプル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; 
/

あなたはRECORDのt_recがネストされたRECORDが含まれている場合、それを行うことができる方法、私を見ることができますか?

はfolowing方法の例を変更します。

-- 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手順を変更する方法ですか? 私は解決策を探すのに何時間も費やしましたが、何か助けに感謝します。

答えて

1

RECORDはPL/SQLデータ型であるため、考えているとは思いません。あなたはOBJECTを作ることによって同等のことをすることができます。 this linkの下にスクロールして(またはページの「オブジェクトを含むレコードを使用して行を更新する:例」を検索すると)、その処理方法がわかります。

+1

はい!私はそのような明白な解決策を見逃す方法を理解していません。どうもありがとうございました。 – giorge

関連する問題