简体   繁体   English

如何使用ODP.Net传递字节数组的数组?

[英]How to pass an array of byte arrays using ODP.Net?

I am trying to pass an array of byte arrays (byte[][]) to Oracle procedure using ODP.Net, which from the Oracle perpective is an array of Raw. 我正在尝试使用ODP.Net将字节数组(byte [] [])的数组传递给Oracle过程,从ODP.Net来看,它是Raw数组。 I get the following exception: 我得到以下异常:

Oracle.DataAccess.Client.OracleException was unhandled by user code Message=ORA-06550: line 1, column 52: PLS-00418: array bind type must match PL/SQL table row type ORA-06550: line 1, column 7: PL/SQL: Statement ignored Source=Oracle Data Provider for .NET ErrorCode=-2147467259 用户代码未处理Oracle.DataAccess.Client.OracleException Message = ORA-06550:第1行,第52列:PLS-00418:数组绑定类型必须与PL / SQL表行类型匹配ORA-06550:第1行,第7列:PL / SQL:语句被忽略Source = .NET的Oracle数据提供程序ErrorCode = -2147467259

I am passing the string arrays to Oracle procedures without any problems, but array of byte arrays is an issue. 我将字符串数组传递给Oracle过程没有任何问题,但是字节数组的数组是一个问题。 Here is my c# code passing byte[][] to the procedure: 这是我的c#代码将byte [] []传递给过程:

conn = new OracleConnection(tm_connectStr);

saveAnswers = new OracleCommand(commandName, conn);
saveAnswers.CommandType = CommandType.StoredProcedure;

// Input params
//byte array of hashed answers.
byte[][] answers = userAnswers.Select(a => a.Answer).ToArray<byte[]>(); //a.Answer is already a byte array.
OracleParameter pAnswers = saveAnswers.Parameters.Add("p_answers_tab", OracleDbType.Raw,     ParameterDirection.Input);
pAnswers.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
pAnswers.Value = answers;
pAnswers.Size = answers.Length;

if (conn.State != ConnectionState.Open) conn.Open();

saveAnswers.ExecuteNonQuery(); //This line throws exception.

The Oracle procedure is: Oracle过程是:

PROCEDURE create_answers(
p_answers_tab IN g_param_raw_tab_type
) IS
BEGIN
FOR i IN p_answers_tab.FIRST .. p_answers_tab.LAST LOOP
INSERT INTO answers
(
answer,
created_ts
)
VALUES (
p_answers_tab( i ),
SYSTIMESTAMP
);
END LOOP;
END create_answers;

And the table structure is: 表结构为:

Table name: Anwers

1) Coulmn name: anwer, Data type: Raw
2) Coulmn name: created_ts, Data type: Timestamp(6)

Any insight is greatly appreciated. 非常感谢任何见解。

The above code is all fine and can be used as is for passing array of byte array to Oracle SPs. 上面的代码都很好,可以将字节数组传递给Oracle SP使用。 Here was the glitch...After beating around the bush for a long time, the DB programmer handling the type "g_param_raw_tab_type" found that the type was inadvertantly made to be an array of varchar instead of Raw. 是一个小故障……经过长时间的摸索之后,处理类型“ g_param_raw_tab_type”的DB程序员发现该类型被无意中制成了varchar数组,而不是Raw数组。 The type was changed to Raw and BINGO!!!! 类型更改为Raw和BINGO !!!! the call went through. 电话打完了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM