c#中无法从Oracle存储过程中检索参数

本文关键字:存储过程 过程中 检索 参数 存储 Oracle | 更新日期: 2023-09-27 18:02:53

这是我的存储过程(为了简单地尝试隔离问题,所以我现在所做的就是设置OUT参数):

DequeuePPLPlatformMsg (msgType OUT VARCHAR2,msgBody OUT VARCHAR2)是开始

    msgType := 'TESTTYPE';
    msgBody := 'TESTBODY';
END DequeuePPLPlatformMsg;

下面是我的c#代码来调用存储过程并尝试获取OUT参数中的值:

            OConn = new OracleConnection();
            OConn.ConnectionString = "Password=mypw; User ID=myid; Data Source=devdb;";
            OConn.Open();
            OComm = new OracleCommand(StoredProc, OConn);
            OComm.CommandType = System.Data.CommandType.StoredProcedure;
        OComm.Parameters.Add("msgType", OracleDbType.Varchar2, 255, System.Data.ParameterDirection.Output);
        OComm.Parameters.Add("msgBody", OracleDbType.Varchar2, 255, System.Data.ParameterDirection.Output);
                int Result = OComm.ExecuteNonQuery();
                OConn.Close();
                String msgType = OComm.Parameters["msgType"].Value.ToString();
                String msgBody = OComm.Parameters["msgBody"].Value.ToString();

当我查看参数中的Values时,它们包含空字符串。

任何想法?谢谢! !

c#中无法从Oracle存储过程中检索参数

对不起,这里是详细信息…

这是存储过程:

程序DequeuePPLPlatformMsg (msgType OUT VARCHAR2, msgBody OUT VARCHAR2) IS BEGIN

msgType := 'TESTTYPE';
msgBody := 'TESTBODY';

DequeuePPLPlatformMsg结束;这是c#代码:

        OConn = new OracleConnection();
        OConn.ConnectionString = "Password=mypw; User ID=myid; Data Source=devdb;";
        OConn.Open();
        OComm = new OracleCommand(StoredProc, OConn);
        OComm.CommandType = System.Data.CommandType.StoredProcedure;
        OracleParameter msgTypeParam = new OracleParameter("msgType", OracleDbType.Varchar2);
        msgTypeParam.Direction = System.Data.ParameterDirection.Output;
        msgTypeParam.Value = "";
        msgTypeParam.Size = 255;
        OComm.Parameters.Add(msgTypeParam);
        OracleParameter msgBodyParam = new OracleParameter("msgBody", OracleDbType.XmlType);
        msgBodyParam.Direction = System.Data.ParameterDirection.Output;
        OComm.Parameters.Add(msgBodyParam);

            int Result = OComm.ExecuteNonQuery();
            OConn.Close();
            String msgType = msgTypeParam.Value.ToString();

msgType是String。空

谢谢!

您是否尝试过简单地按值访问它?

Dim retValParam As New OracleClient.OracleParameter("p_retVal", OracleClient.OracleType.VarChar)
retValParam.Direction = ParameterDirection.Output
retValParam.Size = 100
retValParam.Value = ""
command.Parameters.Add(retValParam)
command.ExecuteNonQuery()
retVal = retValParam.Value