Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# datatypes -> oracle datatypes

I like to save different c# data types in a Oracle database (int, decimal, double, string, Guid, …). Does anyone have a table showing what oracle data types to use?

I have found tables showing what c# data types to use for different oracle data types but not the other way around.

like image 641
Rolf Avatar asked Dec 22 '22 09:12

Rolf


1 Answers

I'm not sure if this helps or not, but this was taken from the ODP.NET assembly using .NET Reflector:

internal static void InsertTableEntries()
{
    s_table.Add(typeof(byte), OracleDbType.Byte);
    s_table.Add(typeof(byte[]), OracleDbType.Raw);
    s_table.Add(typeof(char), OracleDbType.Varchar2);
    s_table.Add(typeof(char[]), OracleDbType.Varchar2);
    s_table.Add(typeof(DateTime), OracleDbType.TimeStamp);
    s_table.Add(typeof(short), OracleDbType.Int16);
    s_table.Add(typeof(int), OracleDbType.Int32);
    s_table.Add(typeof(long), OracleDbType.Int64);
    s_table.Add(typeof(float), OracleDbType.Single);
    s_table.Add(typeof(double), OracleDbType.Double);
    s_table.Add(typeof(decimal), OracleDbType.Decimal);
    s_table.Add(typeof(string), OracleDbType.Varchar2);
    s_table.Add(typeof(TimeSpan), OracleDbType.IntervalDS);
    s_table.Add(typeof(OracleBFile), OracleDbType.BFile);
    s_table.Add(typeof(OracleBinary), OracleDbType.Raw);
    s_table.Add(typeof(OracleBlob), OracleDbType.Blob);
    s_table.Add(typeof(OracleClob), OracleDbType.Clob);
    s_table.Add(typeof(OracleDate), OracleDbType.Date);
    s_table.Add(typeof(OracleDecimal), OracleDbType.Decimal);
    s_table.Add(typeof(OracleIntervalDS), OracleDbType.IntervalDS);
    s_table.Add(typeof(OracleIntervalYM), OracleDbType.IntervalYM);
    s_table.Add(typeof(OracleRefCursor), OracleDbType.RefCursor);
    s_table.Add(typeof(OracleString), OracleDbType.Varchar2);
    s_table.Add(typeof(OracleTimeStamp), OracleDbType.TimeStamp);
    s_table.Add(typeof(OracleTimeStampLTZ), OracleDbType.TimeStampLTZ);
    s_table.Add(typeof(OracleTimeStampTZ), OracleDbType.TimeStampTZ);
    s_table.Add(typeof(OracleXmlType), OracleDbType.XmlType);
    s_table.Add(typeof(OracleRef), OracleDbType.Ref);
}

Internally it looks like ODP.NET uses this (and a few other maps) to determine data types. Also, to handle the NUMBER data type:

internal static OracleDbType ConvertNumberToOraDbType(int precision, int scale)
{
    OracleDbType @decimal = OracleDbType.Decimal;
    if ((scale <= 0) && ((precision - scale) < 5))
    {
        return OracleDbType.Int16;
    }
    if ((scale <= 0) && ((precision - scale) < 10))
    {
        return OracleDbType.Int32;
    }
    if ((scale <= 0) && ((precision - scale) < 0x13))
    {
        return OracleDbType.Int64;
    }
    if ((precision < 8) && (((scale <= 0) && ((precision - scale) <= 0x26)) || ((scale > 0) && (scale <= 0x2c))))
    {
        return OracleDbType.Single;
    }
    if (precision < 0x10)
    {
        @decimal = OracleDbType.Double;
    }
    return @decimal;
}
like image 55
CodingWithSpike Avatar answered Dec 24 '22 22:12

CodingWithSpike