Question

I'm new here. I have a problem. I want to execute this code in C#:

string XMLData = File.ReadAllText(App.FolderImport + "\\" + FileName);

Command.CommandType = CommandType.StoredProcedure;
Command.CommandText = "PKG_DATA_EXCHANGE.IMPORT_DATA";
Command.Parameters.Add("pID_USER_M", OracleType.Number).Value = App.User.IdUser;
Command.Parameters.Add("pFILE_NAME", OracleType.VarChar).Value = FileName;
Command.Parameters.Add("pXMLDATA", OracleType.Clob).Value = XMLDataString;

Command.ExecuteNonQuery();

It works fine for small XMLDataString, but if it is bigger then I get exception ORA-01460.

I understand that it is linked somehow to CLOB problem, but I don't know how to solve it.

I was searching for such problem here, but I had no luck.

Please any help, links or code will be very appreciated!

Was it helpful?

Solution

There are other reported causes of the ORA-01460 as well:

  • Incompatible character sets can cause an ORA-01460
  • Using SQL Developer, attempting to pass a string to a bind variable value in excess of 4000 bytes can result in an ORA-01460
  • With ODP, users moving from the 10.2 client and 10.2 ODP to the 11.1 client and 11.1.0.6.10 ODP reported an ORA-01460 error (this was a bug that should be fixed by patching ODP to the most recent version)

It appears, according to information on bug 5872943, that the ORA-01460 associated with ODP.NET, while not an ODP error, persisted through database version 11.2 where it has been reported as fixed.

OTHER TIPS

A solution is to create an OracleClob object that receives an Open() connection and then we write the value as an Array of Bytes to it.

If you are using EF and Context you can access the conectionString as follows:

string connectionString = _context.Database.GetDbConnection().ConnectionString;

The code would look like this:

using OracleConnection connection = new(connectionString);
    
try
{
    connection.Open(); //required
    
    byte[] arrayByte = System.Text.Encoding.Unicode.GetBytes(audit.AuditRecord);
    OracleClob oracleClob = new (connection);
    oracleClob.Write(arrayByte, 0, arrayByte.Length);

    var parameters = new OracleParameter[]
    {
        new OracleParameter("param1", OracleDbType.Varchar2, valueParam1, ParameterDirection.Input),
        new OracleParameter("param_clob", OracleDbType.Clob, oracleClob, ParameterDirection.Input),
        new OracleParameter("p_refcursor", OracleDbType.RefCursor, ParameterDirection.Output)
    };

    OracleCommand cmd= new("SCHEMA.STORED_PROCEDURE_NAME", connection)
    {
        CommandType = CommandType.StoredProcedure,
    };

    cmd.Parameters.AddRange(parameters);

    cmd.ExecuteNonQuery();
    
    //getting the returned values
    var result = (OracleRefCursor)cmd.Parameters["p_refcursor"].Value;
    var reader = result.GetDataReader();

    reader.Read();

    // To access the returned values

    //reader.GetOracleValue(0)
    //reader.GetOracleValue(1)
    //reader.GetOracleValue(2)
}
finally
{
    connection.Close();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top