`

Oracle and SQL Server Data Type Mapping

阅读更多

2.2 Data Types

This chapter provides detailed descriptions of the differences in data types used by Microsoft SQL Server and Oracle databases. Specifically, this chapter contains the following information:

  • A table showing the base Microsoft SQL Server data types available and how they are mapped to Oracle data types

  • Recommendations based on the information listed in the table

2.2.1 Data Types Table

Table 2-2 Data Types in Oracle and Microsoft SQL Server

Microsoft SQL Server Description Oracle Comments

INTEGER

Four-byte integer, 31 bits, and a sign. May be abbreviated as "INT" (this abbreviation was required prior to version 5).

NUMBER(10)

It is possible to place a table constraint on columns of this type (as an option) to force values between -2^31 and2^31. Or, place appropriate constraints such as: STATE_NO between 1 and 50

SMALLINT

Two-byte integer, 15 bits, and a sign.

NUMBER(6)

It is possible to place a table constraint on columns of this type (optionally) to force values between -2^15 and 2^15. Or, place appropriate constraints such as: STATE_NO between 1 and 50

TINYINT

One byte integer, 8 bits and no sign. Holds whole numbers between 0 and 255.

NUMBER(3)

You may add a check constraint of (x between 0 and 255) where x is column name.

REAL

Floating point number. Storage is four bytes and has a binary precision of 24 bits, a 7-digit precision.

Data can range from –3.40E+38 to 3.40E+38.

FLOAT

The ANSI data type conversion to Oracle for REAL is FLOAT(63). By default, the Oracle Migration Workbench maps REAL to FLOAT(24) that stores up to 8 significant decimal digits in Oracle.

The Oracle NUMBER data type is used to store both fixed and floating-point numbers in a format that is compatible with decimal arithmetic. You may want to add a check constraint to constrain range of values. Also, you get different answers when performing operations on this data type as the Oracle NUMBER type is more precise and portable than REAL. Floating-point numbers can be specified in Oracle in the following format: FLOAT[(b)]. Where [(b)] is the binary precision b and can range from 1 to 126. [(b)] defaults to 126. To check what a particular binary precision is in terms of decimal precision, multiply [(b)] by 0.30103 and round up to the next whole number.

FLOAT

A floating point number. This column has 15-digit precision.

FLOAT

The ANSI data type conversion to Oracle for FLOAT(p) is FLOAT(p). The ANSI data type conversion to Oracle for DOUBLE PRECISION is FLOAT(126). By default, the Oracle Migration Workbench maps FLOAT to FLOAT(53), that stores up to 16 significant decimal digits in Oracle.

The Oracle NUMBER data type is used to store both fixed and floating-point numbers in a format compatible with decimal arithmetic.You get different answers when performing operations on this type due to the fact that the Oracle NUMBER type is much more precise and portable than FLOAT, but it does not have the same range. The NUMBER data type data can range from -9.99.99E+125 to 9.99.99E+125 (38 nines followed by 88 zeros).

NOTE: If you try to migrate floating point data greater than or equal to 1.0E+126 then Migration Workbench will fail to insert this data in the Oracle database and1 will return an error.This also applies to negative values less than or equal to -1.0E+126.




Floating-point numbers can be specified in Oracle using FLOAT[(b)], where [(b)] is the binary precision [(b)] and can range from 1 to 126. [(b)] defaults to 126.To check what a particular binary precision is in terms of decimal precision multiply [(b)] by 0.30103 and round up to the next whole number.

If they are outside of the range, large floating-point numbers will overflow, and small floating-point numbers will underflow.

BIT

A Boolean 0 or 1 stored as one bit of a byte. Up to 8-bit columns from a table may be stored in a single byte, even if not contiguous. Bit data cannot be NULL, except for Microsoft SQL Server 7.0, where null is allowed by the BIT data type.

NUMBER(1)

In Oracle, a bit is stored in a number(1) (or char). In Oracle, it is possible to store bits in a char or varchar field (packed) and supply PL/SQL functions to set / unset / retrieve / query on them.

CHAR(n)

Fixed-length string of exactly n 8-bit characters, blank padded. Synonym for CHARACTER. 0 < n < 256 for Microsoft SQL Server. 0 < n < 8000 for Microsoft SQL Server 7.0.

CHAR(n)

Pro*C client programs must use mode=ansi to have characters interpreted correctly for string comparison, mode=oracle otherwise.

A CHAR data type with a range of 2001 to 4000 is invalid. SQL Developer automatically converts a CHAR datatype with this range to VARCHAR2.

VARCHAR(n)

Varying-length character string. 0 < n < 256 for Microsoft SQL Server. 0 < n < 8000 for Microsoft SQL Server 7.0.

VARCHAR2(n)

 

TEXT

Character string of 8-bit bytes allocated in increments of 2k pages. "TEXT" is stored as a linked-list of 2024-byte pages, blank padded. TEXT columns can hold up to (231-1) characters.

CLOB

The CLOB field can hold up to 4GB.

IMAGE

Binary string of 8-bit bytes. Holds up to (231-1) bytes of binary data.

BLOB

The BLOB field can hold up to 4GB.

BINARY(n)

Fixed length binary string of exactly n 8-bit bytes. 0 < n < 256 for Microsoft SQL Server. 0 < n < 8000 for Microsoft SQL Server 7.0.

RAW(n)/BLOB


VARBINARY(n)

Varying length binary string of up to n 8-bit bytes. 0 < n < 256 for Microsoft SQL Server. 0 < n < 8000 for Microsoft SQL Server 7.0.

RAW(n)/BLOB


DATETIME

Date and time are stored as two 4-byte integers. The date portion is represented as a count of the number of days offset from a baseline date (1/1/1900) and is stored in the first integer. Permitted values are legal dates between 1st January, 1753 AD and 31st December, 9999 AD. Permitted values in the time portion are legal times in the range 0 to 25920000. Accuracy is to the nearest 3.33 milliseconds with rounding downward. Columns of type DATETIME have a default value of 1/1/1900.

DATE

The precision of DATE in Oracle and DATETIME in Microsoft SQL Server is different. The DATETIME data type has higher precision than the DATE data type. This may have some implications if the DATETIME column is supposed to be UNIQUE. In Microsoft SQL Server, the column of type DATETIME can contain UNIQUE values because the DATETIME precision in Microsoft SQL Server is to the hundredth of a second. In Oracle, however, these values may not be UNIQUE as the date precision is to the second. You can replace a DATETIME column with two columns, one with data type DATE and another with a sequence, in order to get the UNIQUE combination. It is preferable to store hundredths of seconds in the second column.

The Oracle TIMESTAMP data type can also be used. It has a precision of 1/10000000th of a second.

SMALL-DATETIME

Date and time stored as two 2-byte integers. Date ranges from 1/1/1900 to 6/6/2079. Time is the count of the number of minutes since midnight.

DATE

With optional check constraint to validate the smaller range.

MONEY

A monetary value represented as an integer portion and a decimal fraction, and stored as two 4-byte integers. Accuracy is to the nearest 1/10,000. When inputting Data of this type it should be preceded by a dollar sign ($). In the absence of the "$" sign, Microsoft SQL Server creates the value as a float.

Monetary data values can range from -922,337,203,685,477.5808 to 922,337,203,685,477.5807, with accuracy to a ten-thousandth of a monetary unit. Storage size is 8 bytes.

NUMBER(19,4)

Microsoft SQL Server inputs MONEY data types as a numeric data type with a preceding dollar sign ($) as in the following example, select * from table_x where y > $5.00 You must remove the "$" sign from queries. Oracle is more general and works in international environments where the use of the "$" sign cannot be assumed. Support for other currency symbols and ISO standards through NLS is available in Oracle.

NCHAR(n)

Fixed-length character data type which uses the UNICODE UCS-2 character set. n must be a value in the range 1 to 4000. SQL Server storage size is two times n.

Note: Microsoft SQL Server storage size is two times n. The Oracle Migration Workbench maps columns sizes using byte semantics, and the size of Microsoft SQL Server NCHAR data types appear in the Oracle Migration Workbench Source Model with "Size" specifying the number of bytes, as opposed to the number of Unicode characters. Thus, a SQL Server column NCHAR(1000) will appear in the Source Model as NCHAR(2000).

CHAR(n*2)


NVARCHAR(n)

Fixed-length character data type which uses the UNICODE UCS-2 character set. n must be a value in the range 1 to 4000. SQL Server storage size is two times n.

Note: Microsoft SQL Server storage size is two times n. The Oracle Migration Workbench maps columns sizes using byte semantics, and the size of Microsoft SQL Server NVARCHAR data types appear in the Oracle Migration Workbench Source Model with "Size" specifying the number of bytes, as opposed to the number of Unicode characters. Thus, a SQL Server column NVARCHAR(1000) will appear in the Source Model as NVARCHAR(2000).

VARCHAR(n*2)


SMALLMONEY

Same as MONEY except monetary data values from -214,748.3648 to +214,748.3647, with accuracy to one ten-thousandth of a monetary unit. Storage size is 4 bytes.

NUMBER(10,4)

Since the range is -214,748.3648 to 214,748.364, NUMBER(10,4) suffices for this field.

TIMESTAMP

TIMESTAMP is defined as VARBINARY(8) with NULL allowed. Every time a row containing a TIMESTAMP column is updated or inserted, the TIMESTAMP column is automatically increment by the system. A TIMESTAMP column may not be updated by users.

NUMBER

You must place triggers on columns of this type to maintain them. In Oracle you can have multiple triggers of the same type without having to integrate them all into one big trigger. You may want to supply triggers to prevent updates of this column to enforce full compatibility.

SYSNAME

VARCHAR(30) in Microsoft SQL Server.

NVARCHAR(128) in Microsoft SQL Server 7.0.

VARCHAR2(30) and VARCHAR2(128) respectively.

 

<!-- class="tblformal" -->

TEXT and IMAGE data types in Microsoft SQL Server follow these rules:

  • The column of these data types cannot be indexed.

  • The column cannot be a primary key.

  • The column cannot be used in the GROUP BY, ORDER BY, HAVING, and DISTINCT clauses.

  • IMAGE and TEXT data types can be referred to in the WHERE clause with the LIKE construct.

  • IMAGE and TEXT data types can also be used with the SUBSTR and LENGTH functions.

In Microsoft SQL Server, only columns with variable-length data types can store NULL values. When you create a column that allows NULLs with a fixed-length data type, the column is automatically converted to a system variable-length data type, as illustrated in Table 2-3. These variable-length data types are reserved system data types, and users cannot use them to create columns

Table 2-3 Data Type Conversion for NULL Values

Fixed-Length Data Type Variable-Length Data Type

CHAR

VARCHAR

NCHAR

NVARCHAR

BINARY

VARBINARY

DATETIME, SMALLDATETIME

DATETIMN

FLOAT

FLOATN

INT, SMALLINT, TINYINT

INTN

DECIMAL

DECIMALN

NUMERIC

NUMERICN

MONEY, SMALLMONEY

MONEYN


<!-- class="tblformal" -->

Note:

The Oracle Migration Workbench Source Model will display table system data types for each column.

Recommendations

In addition to the data types listed in Table 2-2, users can define their own data types in Microsoft SQL Server databases. These user-defined data types translate to the base data types that are provided by the server. They do not allow users to store additional types of data, but can be useful in implementing standard data types for an entire application.

You can map data types from Microsoft SQL Server to Oracle with the equivalent data types listed in Table 2-3. SQL Developer converts user-defined data types to their base type. You can defined how the base type is mapped to an Oracle type in the Data Type Mappings page in the Options dialog.

<!-- class="sect2" -->
分享到:
评论

相关推荐

    c# 做成数据库生成 nhibernate映射文件程序,包括oracle 和sql server

    这需要配置正确的连接字符串,并使用适当的Oracle(如ODP.NET)或SQL Server(如System.Data.SqlClient)提供者。 2. 数据库元数据获取:通过执行SQL查询或使用特定的数据库API来获取表结构、列信息、主键和外键...

    jboss数据库配置+oracle+mysql+sqlserver

    &lt;type-mapping&gt;mySQL&lt;/type-mapping&gt; &lt;!-- 数据库类型映射,这里保持默认即可 --&gt; &lt;/datasources&gt; ``` - **放置位置**: 修改后的 `mysql-ds.xml` 文件需要放置到 `tobeyou**\server\default\deploy` 目录下。 ...

    通过SSIS导入数据(SQL Server2005-->Oracle11g)

    ### 通过SSIS导入数据(SQL Server2005→Oracle11g) #### 一、概述 在数据集成和迁移场景中,SQL Server Integration Services (SSIS) 是一种非常强大的工具,它允许用户轻松地从不同的数据源抽取、转换和加载...

    Devart_UniDAC_6.3.13_for_XE8

    SQLServer data provider Data type mapping from Varbinary type to Blob field is added Bug with data type mapping from MONEY type to TBCDField field is fixed Bug with AV failure on project compilation ...

    Devart_UniDAC_6.3.13_for_DX10.1

    SQLServer data provider Data type mapping from Varbinary type to Blob field is added Bug with data type mapping from MONEY type to TBCDField field is fixed Bug with AV failure on project compilation ...

    RComponent.DataObject

    Sql Server,DB2, Oracle, Access, Ase, Query by object,Paging, criteria, Mapping behaviour, mutil connection support, Data save and get, No XML mapping. Supports all of C#, C++ and VB languages. ...

    NHibernate Mapping Generator

    1. Supports Oracle, SqlServer, PostgreSQL, MySQL, SQLite, Sybase, Ingres, CUBRID 2. Can generate hbm.xml, Fluent NHibernate and NH 3.3 Fluent style of mapping files. 3. Has lots of preferences to ...

    Devart UniDAC v5.3.10 Full Source

    -Data type mapping from RAW(16) to ftGuid is added -Now result parameter detection in UniConnection.ExecSQL is similar to the one in ODAC -Bug with connection establishing if the client has negative ...

    Applied ADO.NET: Building Data-Driven Solutions(2)

    Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers Chapter 13 - Developing a Custom Data Provider Chapter 14 - Developing Database Web Applications using ASP.NET Chapter 15 - Using ADO...

    Postgresql连接oracle驱动并实现读写

    CREATE SERVER ora_client_dw1 FOREIGN DATA WRAPPER oracle_fdw OPTIONS (dbserver '//134.132.9.7:1521/dw'); CREATE USER MAPPING FOR postgres SERVER ora_client_dw1 OPTIONS (user 'dw', password 'xxxx'); ...

    unidac 7.4.11 pro for RAD Studio 10.3

    Bug with updating fields which have data type mapping in TVirtualQuery is fixed Oracle data provider Oracle 18c is supported Implicit result sets in Oracle 12 are supported Bug with detecting time ...

    Applied ADO.NET: Building Data-Driven Solutions(1)

    Chapter 11 - Stored Procedures and Views Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers Chapter 13 - Developing a Custom Data Provider Chapter 14 - Developing Database Web ...

    Devart UniDAC 7.4.11 Professional for RAD Studio 10.3 Rio

    Bug with updating fields which have data type mapping in TVirtualQuery is fixed Oracle data provider Oracle 18c is supported Implicit result sets in Oracle 12 are supported Bug with detecting time ...

    UnidacPro8.0.1Rio.rar

    v8.0.1 RAD Studio 10.3 Rio is supported Support of UPPER and LOWER functions for Unified SQL is added Bug with using the FieldOrigins property is fixed Bug with using the TrimFixedChar property is ...

    UnidacProv8.0.1Tokyo.rar

    v8.0.1 RAD Studio 10.2 Tokyo is supported Support of UPPER and LOWER functions for Unified SQL is added Bug with using the FieldOrigins property is fixed Bug with using the TrimFixedChar property is ...

    OracleHelper oracle数据库访问 多种方式 可靠 强大

    在数据访问方面,OracleHelper可能支持ADO.NET、ODP.NET(Oracle Data Provider for .NET)等多种.NET框架下的数据访问技术。ADO.NET提供了基础的数据访问接口,而ODP.NET是Oracle官方提供的专用.NET数据提供者,它...

    unidac 5.2.5

    SQLServer data provider Bug with incorrect committing of data by the Loader component on errors is fixed MySQL data provider Bug with connecting in the Direct mode under Windows 2000 and lower is ...

    JBoss 下配置 Oracle 数据源

    &lt;type-mapping&gt;Oracle9i&lt;/type-mapping&gt; &lt;min-pool-size&gt;10 &lt;max-pool-size&gt;30 &lt;blocking-timeout-millis&gt;60000 &lt;idle-timeout-minutes&gt;2 &lt;new-connection-sql&gt;SELECT COUNT(*) FROM dual&lt;/new-connection-...

    使用JDBC和Hibernate来写入Blob型数据到Oracle中

    要向Oracle数据库写入Blob数据,我们首先需要加载Oracle的JDBC驱动,建立数据库连接,然后创建PreparedStatement对象来执行SQL插入语句。插入语句通常包含一个占位符(?),对应于Blob类型的值。在执行前,我们需要...

    LINQ to SQL和Entity Framework对比与关联

    - **支持多数据库**:除了 SQL Server 外,EF 还支持 Oracle、MySQL 等多种数据库系统。 - **性能与复杂度权衡**:虽然 EF 提供了更多的灵活性,但这种灵活性是以牺牲一定的性能和增加一定的复杂性为代价的。 ###...

Global site tag (gtag.js) - Google Analytics