c# 数据类型-> oracle 数据类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1334574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:53:06  来源:igfitidea点击:

c# datatypes -> oracle datatypes

c#oracletypesodp.net

提问by Rolf

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?

我喜欢在 Oracle 数据库中保存不同的 c# 数据类型(int、decimal、double、string、Guid 等)。有没有人有一张表显示要使用的 oracle 数据类型?

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

我找到了一些表格,显示了用于不同 oracle 数据类型的 c# 数据类型,但不是相反。

回答by CodingWithSpike

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

我不确定这是否有帮助,但这是从使用 .NET Reflector 的 ODP.NET 程序集获取的:

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:

在内部看起来 ODP.NET 使用这个(和一些其他映射)来确定数据类型。此外,要处理 NUMBER 数据类型:

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