简体   繁体   中英

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

When I try to run a package on our oracle database from Oracle's .net provider, or the Microsoft oracle provider, it gives me the following error:

{"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"}

Here is my C# code:

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(); 

Here is my package definition:

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

When I uncomment the third parameter that I've added, I get a different error:

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

Try following code:

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();
}

Comment:

Don't forgive wrap disposable objects in using construction.

I removed the username from the package definition, and also uncommented my add parameter for the return value.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM