3

Oracle 11g で次のオブジェクトを作成しました。

CREATE OR REPLACE TYPE myObject as object(
fieldOne number,
fieldTwo number
);

そして、myObject の新しいテーブル タイプを作成しました。

CREATE OR REPLACE TYPE myTable IS TABLE OF myObject;

ここで、myTable の新しいインスタンスを作成し、いくつかのハードコードされmyTableた行を SQL Plus コマンド ラインに追加して、オブジェクトをmyProcedureパラメーターとして渡したいと思います。

私は次のことを試しました。

declare newTable myTable;
begin
select myObject(50,5) bulk collect into newTable from dual;
select myObject(40,7) bulk collect into newTable from dual;
myProcedure(newTable);
commit;
end;

select into2 番目のステートメントが最初のステートメントを上書きしますが、どちらの種類が機能しますか。

私の質問は; 複数の行を newTable に追加するにはどうすればよいですか?

よろしくお願いします:)

4

1 に答える 1

4
declare
    newTable myTable;
begin
    newTable := myTable();
    newTable.extend(2); -- The desired size of the collection

    -- Oracle collections begin at index 1, not 0
    newTable(1) := myObject(50, 5);
    newTable(2) := myObject(40, 7);

    myProcedure(newTable);
end;
于 2013-01-20T21:15:26.033 に答える