无法使用 OracleManagedDataAccess 从 oracle 存储过程中检索出参数

Posted

技术标签:

【中文标题】无法使用 OracleManagedDataAccess 从 oracle 存储过程中检索出参数【英文标题】:Cannot retrieve out parameters from oracle stored procedure using OracleManagedDataAccess 【发布时间】:2016-02-24 21:28:22 【问题描述】:

经过一番努力,我在这里写了我的问题,并尝试了所有可用的在线选项。 这是我的问题。我正在使用 ODP.Net、oracleManagedDataAccess 库连接到 oracle 数据库。我有一个带有输入和输出参数的存储过程,当我从 pl/sql 测试它时工作正常,但当我尝试从我的 .net 代码执行它时并检索它们返回 null 的 out 参数,如果我看到每个 out 参数的状态,它的 false 和值是“Null Fetched”,并且参数的大小显示为 0,尽管我将参数的大小设置为字符串类型为 4000。请在下面查看我的代码。请帮忙。正如我之前告诉你的,我的存储过程在 pl/sql 中工作得很好。

connection = new OracleConnection(DBHelper.ConnectionString); 连接.Open();

           command = new OracleCommand();
           command.Connection = connection;
           command.CommandType = System.Data.CommandType.StoredProcedure;
           command.CommandText = DBConstants.PROC_GETBORROWERSEQNO;

           //Input
           command.Parameters.Add("password", OracleDbType.Varchar2, 4000, password, ParameterDirection.Input);
           command.Parameters.Add("userid", OracleDbType.Varchar2, 4000, userID, ParameterDirection.Input);
           command.Parameters.Add("ipaddress", OracleDbType.Varchar2,4000, iPAddress, ParameterDirection.Input);    


           //Output                                
           command.Parameters.Add("shawcustno", OracleDbType.Decimal).Direction = ParameterDirection.Output;
           command.Parameters.Add("emailid", OracleDbType.Varchar2,4000).Direction = ParameterDirection.Output;
           command.Parameters.Add("contr_phase", OracleDbType.Varchar2, 4000).Direction = ParameterDirection.Output;
           command.Parameters.Add("source_seqno", OracleDbType.Decimal,15).Direction = ParameterDirection.Output;
           command.Parameters.Add("borrower_seqno", OracleDbType.Decimal,15).Direction = ParameterDirection.Output;
           command.Parameters.Add("pag_phone", OracleDbType.Varchar2, 4000).Direction = ParameterDirection.Output;  

           command.Parameters.Add("pag", OracleDbType.Varchar2, 4000).Direction = ParameterDirection.Output;

           //InputOutput
           command.Parameters.Add("sessionseqno", OracleDbType.Decimal).Direction = ParameterDirection.InputOutput;

           sequenceNumber = command.ExecuteNonQuery();
           customer = new Customer();
           customer.Company = command.Parameters["company"].Value.ToString();
           customer.Pag = command.Parameters["pag"].GetString();
           customer.PagPhone = command.Parameters["pag_phone"].GetString();
           customer.BorrowerSeqNo = command.Parameters["borrower_seqno"].IsDBNull() ? 0 :    command.Parameters["borrower_seqno"].GetInt32();
           customer.SourceSeqNo = command.Parameters["source_seqno"].IsDBNull() ? 0 :    command.Parameters["source_seqno"].GetInt32(); 
           customer.EmailID = command.Parameters["emailid"].GetString();
           customer.ShawCustNo = command.Parameters["shawcustno"].GetString();
           customer.SessionSeqNo = command.Parameters["sessionseqno"].IsDBNull() ? 0 :    command.Parameters["sessionseqno"].GetInt32();                
       

【问题讨论】:

【参考方案1】:

终于找到答案了,参数的顺序必须和存储过程中声明的顺序完全一样。我错过了那个订单。

【讨论】:

以上是关于无法使用 OracleManagedDataAccess 从 oracle 存储过程中检索出参数的主要内容,如果未能解决你的问题,请参考以下文章

无法使用 StorageClass 配置卷 - 无法获取存储帐户的存储密钥

Worklight Studio 和本地开发,有时无法使用 Java 类,有时无法使用 HTML 文件

ADB无法使用解决办法

Ubuntu 80端口无法使用-非root用户无法使用1024以下端口

无法在 SQL Server 视图中使用工作查询:“IS”无法识别“>”无法识别

LINUX下的mail\mailx为啥无法使用外部SMTP发邮件