嗨,我有这个程序:
DECLARE
I_BIG_INSTITUTION_CODE VARCHAR2(10);
I_BIG_ACTION_CODE VARCHAR2(10);
O_CASES_TAB MY_API.VARCHAR_TAB;
I_USER VARCHAR2(200);
I_AD_USER VARCHAR2(200);
I_LANGUAGE VARCHAR2(200);
I_ASYS_ID NUMBER;
O_RESULT_SUCCESSFUL BINARY_INTEGER;
O_MESSAGE VARCHAR2(200);
BEGIN
I_BIG_INSTITUTION_CODE := 'KRD';
I_BIG_ACTION_CODE := 'ADD';
I_USER := 'User User';
I_AD_USER := 'u.user';
I_LANGUAGE := 'PL';
I_ASYS_ID := 100;
MY_API.PACKAGE_NAME.GET_PACK_TO_SEND(
I_BIG_INSTITUTION_CODE => I_BIG_INSTITUTION_CODE,
I_BIG_ACTION_CODE => I_BIG_ACTION_CODE,
O_CASES_TAB => O_CASES_TAB,
I_USER => I_USER,
I_AD_USER => I_AD_USER,
I_LANGUAGE => I_LANGUAGE,
I_ASYS_ID => I_ASYS_ID,
O_RESULT_SUCCESSFUL => O_RESULT_SUCCESSFUL,
O_MESSAGE => O_MESSAGE);
if O_CASES_TAB.count>0 then
for i in O_CASES_TAB.first..O_CASES_TAB.last loop
DBMS_OUTPUT.PUT_LINE('O_CASES_TAB = ' || O_CASES_TAB(i));
end loop;
end if;
DBMS_OUTPUT.PUT_LINE('O_RESULT_SUCCESSFUL = ' || O_RESULT_SUCCESSFUL);
DBMS_OUTPUT.PUT_LINE('O_MESSAGE = ' || O_MESSAGE);
END;
该过程返回如下内容: Procedure result
现在,我需要阅读C#中的 o_cases_tab 参数,但是我不知道该怎么做。这是尝试执行此操作的代码:
public void GetPackToSend()
{
using (var connection = ConnectionFactory.GetConnection())
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "MY_API.PACKAGE_NAME.GET_PACK_TO_SEND";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("input_parameter1", OracleDbType.NVarchar2).Value = "value_1" ;
command.Parameters.Add("input_parameter2", OracleDbType.NVarchar2).Value = "value_2";
AddOutArrayParameter(command, "o_cases_tab", "MY_API.VARCHAR_TAB", 10);
command.Parameters.AddRange(OracleParameterHelper.GetDefaultInputParameters()
.ToArray());
command.Parameters.AddRange(OracleParameterHelper.GetDefaultOutputParameters().ToArray());
try
{
command.ExecuteNonQuery();
var dbResult = new Tuple<string, string, object>(
command.Parameters["o_result_successful"].Value.ToString(),
command.Parameters["o_message"].Value.ToString(),
command.Parameters["o_cases_tab"].Value);
}
catch (OracleException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
}
dbResult = {(1,null,System.Object [])} 因此,在参数 o_cases_tab 中,我有: System.Object []
方法addOutArrayParameter
private static void AddOutArrayParameter(OracleCommand command, string paramName,
string paramTypeName, int size = 1)
{
var parameter = command.CreateParameter();
parameter.Size = size;
parameter.ArrayBindSize = size;
parameter.UdtTypeName = paramTypeName;
parameter.ParameterName = paramName;
parameter.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
parameter.Direction = ParameterDirection.Output;
parameter.OracleDbType = OracleDbType.Array;
command.Parameters.Add(parameter);
}
我肯定是在犯一个愚蠢的错误,但是我第一次使用oracle,所以我要放纵自己。