Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read oracle tables using .NET, one LONG type column always returns empty string, how to solve it?

Tags:

c#

.net

oracle

I am reading from a table all_tab_columns, there is a "data_default" column, which is a type of LONG.

If I query the oracle server using sqlplus, such as "select data_default from all_tab_columns where table_name='testtable'", everything is fine. The correct default value for each columns of the table "testtable" can be returned.

But if I use the Oracle.ManagedDataAccess.dll (well, I am using Spartacus library, which in turn uses Oracle.ManagedDataAccess.dll), for the same query, the data_default column always returns empty string '', I tried several other columns such as column_name, table_name, owner etc. they are all fine.

My question is how do I debug such case? I couldn't locate the root cause of this peculiar error. Any suggestion will be welcome.

Thanks.


The source code for spartacus to read from oracle is as follows,

this.v_con = new OracleManaged.OracleConnection(this.v_connectionstring);
this.v_con.Open();
this.v_cmd = new OracleManaged.OracleCommand(p_sql, this.v_con);
if (this.v_timeout > -1)
    this.v_cmd.CommandTimeout = this.v_timeout;
this.v_reader = this.v_cmd.ExecuteReader();

v_table = new System.Data.DataTable(p_tablename);
for (int i = 0; i < this.v_reader.FieldCount; i++)
    v_table.Columns.Add(this.v_reader.GetName(i), typeof(string));

while (this.v_reader.Read())
{
    v_row = v_table.NewRow();
    for (int i = 0; i < this.v_reader.FieldCount; i++)
        v_row[i] = this.v_reader[i].ToString();
    v_table.Rows.Add(v_row);
}

I tried to debug, the v_reader[i].ToString() for data_default column is empty already. Seems there's no way for me to solve it? Is it probably the .dll problem?

like image 272
user534498 Avatar asked Jan 30 '17 08:01

user534498


People also ask

What is RAW data type in Oracle?

RAW. The RAW datatype is used for binary data or byte strings that are not to be interpreted by Oracle, for example, to store graphics character sequences. The maximum length of a RAW column is 2000 bytes.

What is a long data type in Oracle?

The LONG datatype can store variable-length character data containing up to two gigabytes of information. The length of LONG values might be limited by the memory available on your computer. You can use columns defined as LONG in SELECT lists, SET clauses of UPDATE statements, and VALUES clauses of INSERT statements.

What is CHAR data type in Oracle?

The CHAR datatype specifies a fixed-length character string. Oracle ensures that all values stored in a CHAR column have the length specified by size . If you insert a value that is shorter than the column length, then Oracle blank-pads the value to column length.

What do you mean by data type in Oracle explain some data types in Oracle?

Each value manipulated by Oracle Database has a data type. The data type of a value associates a fixed set of properties with the value. These properties cause Oracle to treat values of one data type differently from values of another.


1 Answers

Obtaining LONG and LONG RAW Data

ODP.NET fetches and caches rows from the database during the Read method invocations on the OracleDataReader object. The amount of LONG and LONG RAW column data that is retrieved from this operation is determined by InitialLONGFetchSize. More

You may need to set the InitialLONGFetchSize to a non-zero value and use the OracleDataReader's GetOracleString() method, and use ToString() to convert the result into a .Net string.

like image 162
atokpas Avatar answered Oct 06 '22 10:10

atokpas