James Wang Blog

Datatypes translation between Oracle and SQL Server part 1: character, binary strings


Datatypes translation is one of the most important things you need to consider when migrate your application from one database to the other. This is an article in the series that we talking about translate SQL query among different databases.

This article will focused on conversion of those datatypes: character, binary strings between Oracle and SQL Server. We will talk about conversion of other datatypes such as nunber, float, date and etc in other articles later.

When you convert character datatypes from Oracle to SQL Server or vice verse, you not only need to find corresponding datatype name but also need to find out how string was stored in database. Is this string stored in character or byte? and you must be aware of the maximum length of datatype in source and target databases.

In SQL Server, char [ ( n ) ] is fixed-length, non-Unicode character data with a length of n bytes. n must be a value from 1 through 8,000. You can easily find corresponding datatype name “char” in Oracle, but char in oracle with a maximum length of 2000 bytes. So you can’t migrate char(2048) in your SQL Server script to Oracle without any changes, you should use clob instead if n > 2000.

In Oracle database, char[(size)] can be also be used in fixed-length character data of length size in characters. When you use char qualifier, for example char(10 char), then you supply the column length in characters. A character is technically a code point of the database character set. Its size can range from 1 byte to 4 bytes, depending on the database character set. When translate this datatype to SQL Server, target datatype can be char(10) or char(40) depends on the database character set in source database(Oracle).

Detailed information about Oracle datatypes and SQL Server datatypes: including datatype name, description and what’s the corresponding datatype in other databases.

Below are summary tables show how Character and binary string datatypes translated from Oracle to SQL Server and vice verse.

Oracle(source) SQL Server(target)
CHAR [(size [BYTE | CHAR])] char[(size)]
VARCHAR2(size [BYTE | CHAR]) varchar(size)
NCHAR[(size)] nchar[(size)]
NVARCHAR2(size) nvarchar(size)
long varchar(max)
long raw varbinary(max)
raw(size) varbinary(size)
blob varbinary(max)
clob varchar(max)
nclob ntext
bfile N/A

How Character and binary string datatypes translated from SQL Server to Oracle.
SQL Server(source) Oracle(target)
char [ ( n ) ] char[(n)], 1<=n<=2000; clob, n>2000
varchar [ ( n | max ) ] varchar2(n), 1<=n<=4000; clob (n>4000)
text clob
nchar [ ( n ) ] nchar[(n)], 1<=n<=2000; nclob(n>2000)
nvarchar [ ( n | max ) ] nvarchar2[(n)], 1<=n<=4000; nclob( n>4000 )
ntext nclob
binary [ ( n ) ] raw(1)(n was omitted); raw(n), 1<=n<=2000; blob(n>2000)
varbinary [ ( n | max) ] raw(1)(n was omitted); raw(n), 1<=n<=2000; blob(n>2000)
image blob

Legacy Comments


Suresh Reddy
2011-07-11
re: Datatypes translation between Oracle and SQL Server part 1: character, binary strings
Thanks

Discount Mulberry Bags
2011-08-07
re: Datatypes translation between Oracle and SQL Server part 1: character, binary strings
I obtained a amount of compliments from my pals or coworkers simply because they are surely eager to purchase mulberry alexa bag.

Mulberry for Target
2011-08-17
Mulberry for Target
This is why the key reason why you simply must opt for attentively. In order that want you to manufacture complete choice while looking for a fresh wives Mulberry Ledbury Handbag, you simply must think about several products