Running Oracle Package: ORA-06550 || ORA-06502

本文关键字:ORA-06502 ORA-06550 Oracle Package Running | 更新日期: 2023-09-27 17:52:47

当我尝试从oracle的。net提供程序或Microsoft oracle提供程序在oracle数据库上运行包时,它给了我以下错误:

{"ORA-06550: line 1, column 7:'nPLS-00221: 'BEGIN_TRANSACTION' is not a procedure or is undefined'nORA-06550: line 1, column 7:'nPL/SQL: Statement ignored"}
下面是我的c#代码:
OracleConnection cn = new OracleConnection(connectionString);
OracleCommand cmd = new OracleCommand();
cmd.Connection = cn;
cmd.CommandText = "DOTNET.SYSTEM_CRUD.BEGIN_TRANSACTION";
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("p_user_id", OracleDbType.Decimal, ParameterDirection.Input).Value = 4720;
cmd.Parameters.Add("p_commt", OracleDbType.Varchar2, ParameterDirection.Input).Value = "TEST";
//cmd.Parameters.Add("return_value", OracleDbType.Decimal).Direction = ParameterDirection.ReturnValue;
cmd.ExecuteNonQuery(); 

这是我的包定义:

Function Begin_Transaction ( p_user_id  IN NUMBER,
                             p_commt    IN  VARCHAR2
                            )
  RETURN Number;

当我取消注释我添加的第三个参数时,我得到了一个不同的错误:

{"ORA-06502: PL/SQL: numeric or value error: character to number conversion error'nORA-06512: at line 1"}

Running Oracle Package: ORA-06550 || ORA-06502

试试下面的代码:

using (OracleCommand cmd = new OracleCommand())
{
    cmd.Connection = cn;
    cmd.CommandText = "DOTNET.SYSTEM_CRUD.BEGIN_TRANSACTION";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.BindByName = true;
    cmd.Parameters.Add(new OracleParameter("p_user_id", OracleDbType.Decimal, 4720, ParameterDirection.Input));
    cmd.Parameters.Add(new OracleParameter("p_commt", OracleDbType.Varchar2, "TEST", ParameterDirection.Input));
    cmd.ExecuteNonQuery();
}

评论:

不要原谅在using结构中包装一次性对象。

我从包定义中删除了用户名,并取消了返回值的add参数的注释。

using (OracleConnection cn = new OracleConnection(connectionString))
            {
                using (OracleCommand cmd = new OracleCommand())
                {
                    cmd.Connection = cn;
                    cmd.CommandText = "SYSTEM_CRUD.BEGIN_TRANSACTION";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.BindByName = true;

                    cmd.Parameters.Add("p_user_id", OracleDbType.Decimal, ParameterDirection.Input).Value = 4720;
                    cmd.Parameters.Add("p_commt", OracleDbType.Varchar2, ParameterDirection.Input).Value = "TEST";
                    cmd.Parameters.Add("return_value", OracleDbType.Decimal).Direction = ParameterDirection.ReturnValue;
                    cmd.ExecuteNonQuery();