0

Pl-Sql のビジネス ロジックと C# の GUI を持つプロジェクトに取り組んでいます。

files次のようにテーブルを表すPl-Sqlにレコードタイプがあります。

type file_record is record(
    id        number
   ,file_name varchar2(256));

type file_record_type is table of file_record index by pls_integer;

すべてのエントリをテーブルに取得して C# に渡したい。

Pl-Sql 手順は次のとおりです。

procedure get_all_file_names(p_files out file_record_type) is

v_counter number := 1;

begin

for c in (select id
                ,file_name
            from files) loop
  p_files(v_counter).id := c.id;
  p_files(v_counter).file_name := c.file_name;
  v_counter := v_counter + 1;
end loop;

end get_all_file_names;

そして、次のように C# 経由でこの手順を呼び出しています。

// get pmp entries from inside a specific file
    public DataSet getAllPmpFileNames(string commandText)
    {
        DataSet dataSet = new DataSet();

        OracleCommand oracleCommand = new OracleCommand();

        OracleParameter oracleParameter = new OracleParameter("p_files", OracleDbType.Object);
        oracleParameter.Direction = ParameterDirection.Output;
        oracleParameter.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
        oracleCommand.Parameters.Add(oracleParameter);

        oracleCommand.CommandText = commandText;
        oracleCommand.CommandType = CommandType.StoredProcedure;

        try
        {
            oracleCommand.Connection = m_Connection;
            OracleDataAdapter oracleDataAdapter = new OracleDataAdapter(oracleCommand);
            oracleDataAdapter.Fill(dataSet);
        }
        catch (Exception)
        {
            throw;
        }

        return dataSet;
    }

これを C# から呼び出すと、例外が発生しますOracleParameter.Size is invalid

わからないので、電話する前にサイズを伝えることはできません. 最初にサイズを取得してからプロシージャを呼び出す必要がありますか?

または、C# から複数のデータベース要素に到達する他のエレガントな方法はありますか?

4

1 に答える 1

0

ストアド プロシージャの代わりにビューを作成し、OracleDataReader を使用して DataSet を設定します。

于 2013-05-03T18:07:07.153 に答える