Enterprise Library ODP.NET调用返回ORA-06502:PL / SQL:数字或值错误

时间:2013-12-11 17:18:10

标签: c# oracle enterprise-library odp.net enterprise-library-6

我有以下Oracle存储过程:

PROCEDURE SP_ITEMEXISTS(pID IN NUMBER, pExists OUT CHAR) IS
BEGIN
        select CASE count(*) WHEN 0 THEN 'N' ELSE 'Y' END into pExists from items where id = pID;
END SP_ITEMEXISTS;

我使用ODP.NET从Enterprise Library 6.0中调用它,代码如下:

public bool ItemExists(int itemID)
{
    string procedureName = "SP_ItemExists";
    var database = new DatabaseProviderFactory().CreateDefault();
    bool returnValue = false;

    using (OracleCommand command = (OracleCommand)database.GetStoredProcCommand(procedureName))
        {
            command.Parameters.Add("pID", OracleDbType.Int32, itemID, ParameterDirection.Input);
            OracleParameter pExists = command.Parameters.Add("pExists", OracleDbType.Char, ParameterDirection.Output);

            database.ExecuteNonQuery(command);

            if (pExists.Value.ToString().ToUpper() == "Y")
                returnValue = true;
            else
                returnValue = false;
        }

    return returnValue;

}

我收到以下错误: ORA-06502:PL / SQL:数字或值错误

从Oracle SQL Developer调用存储过程可以正常工作。

1 个答案:

答案 0 :(得分:0)

似乎是像这里一样的问题:How to Convert Datetime to OracleTimeStamp

您必须指定返回值的大小,即

OracleParameter pExists = command.Parameters.Add("pExists", OracleDbType.Char, 1, null, ParameterDirection.Output);