1

I am using the Oracle.ManagedDataAccess.Client to get data from Oracle into C#. My return value I am retrieving is a Clob:

 cmd.Parameters.Add("return_value", OracleDbType.Clob).Direction =
   ParameterDirection.ReturnValue;

I cannot seem to convert this into a string or anything C# recognises.

7
  • Please share a minimal reproducible example. Commented Aug 3, 2020 at 7:45
  • docs.oracle.com/cd/E85694_01/ODPNT/… Commented Aug 3, 2020 at 7:57
  • How are you trying though? Clobs are streams so you'll probably be looking at something like var s = new StreamReader(parameter.Value).ReadToEnd() Commented Aug 3, 2020 at 8:48
  • I am doing, string test = cmd.Parameters["return_value"].Value.ToString(); but it isn't working. I tried new StreamReader(cmd.Parameters["return_value"].Value.).ReadToEnd(), but it is saying it cannot convert from object to System.IO.Stream Commented Aug 3, 2020 at 9:08
  • What is cmd.Parameters["return_value"].Value.GetType()? Commented Aug 3, 2020 at 9:29

3 Answers 3

2

I managed to do it with this:

OracleClob myLob = (OracleClob)cmd.Parameters[0].Value;
                    ret_string = Convert.ToString(myCLob.Value);
Sign up to request clarification or add additional context in comments.

Comments

0

Did you try something like (where clob is your Clob)?

string clobValue = (string) clob.Value;

According to this solution it should work: Converting a large CLOB object to .NET string to put into a DataGridView cell

1 Comment

When I do that, I get Oracle.ManagedDataAccess.Types.OracleClob. When I debug, I can go to cmd and then parameters, and then return_value, the value property has 'Oracle.ManagedDataAccess.Types.OracleClob', but when I expand Value, it has another value property with the string I want.
0

I use this

string clob_str = ((OracleClob)Command.Parameters["return_value"].Value).Value;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.