{"id":494,"date":"2010-07-28T21:17:35","date_gmt":"2010-07-29T02:17:35","guid":{"rendered":"http:\/\/www.dpriver.com\/blog\/?p=494"},"modified":"2011-09-26T21:48:27","modified_gmt":"2011-09-27T02:48:27","slug":"datetypes-conversion-between-oracle-and-sql-server","status":"publish","type":"post","link":"https:\/\/www.dpriver.com\/blog\/2010\/07\/datetypes-conversion-between-oracle-and-sql-server\/","title":{"rendered":"Datatypes translation between Oracle and SQL Server part 1: character, binary strings"},"content":{"rendered":"

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 one of the series of articles that we talking about translate SQL query among different databases.<\/a><\/p>\n

\nThis 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.\n<\/p>\n

\nWhen 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.\n<\/p>\n

\nIn 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.\n<\/p>\n

\nIn 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).\n<\/p>\n

\nDetailed information about Oracle datatypes<\/a> and SQL Server datatypes<\/a>: including datatype name, description and what’s the corresponding datatype in other databases.\n<\/p>\n

\nBelow are summary tables show how Character and binary string datatypes translated from Oracle to SQL Server and vice verse.\n<\/p>\n

\n

\n
\nOracle(source)<\/td>\n | SQL Server(target)<\/td>\n<\/tr>\n
\nCHAR [(size [BYTE | CHAR])]<\/td>\n | char[(size)]<\/td>\n<\/tr>\n
\nVARCHAR2(size [BYTE | CHAR])<\/td>\n | varchar(size)<\/td>\n<\/tr>\n
\nNCHAR[(size)]<\/td>\n | nchar[(size)]<\/td>\n<\/tr>\n
\nNVARCHAR2(size)<\/td>\n | nvarchar(size)<\/td>\n<\/tr>\n
\nlong<\/td>\n | varchar(max)<\/td>\n<\/tr>\n
\nlong raw<\/td>\n | varbinary(max)<\/td>\n<\/tr>\n
\nraw(size)<\/td>\n | varbinary(size)<\/td>\n<\/tr>\n
\nblob<\/td>\n | varbinary(max)<\/td>\n<\/tr>\n
\nclob<\/td>\n | varchar(max)<\/td>\n<\/tr>\n
\nnclob<\/td>\n | ntext<\/td>\n<\/tr>\n
\nbfile<\/td>\n | N\/A<\/td>\n<\/tr>\n<\/table>\n<\/div>\n \nHow Character and binary string datatypes translated from SQL Server to Oracle.\n<\/p>\n \n \n
\nSQL Server(source)<\/td>\n | Oracle(target)<\/td>\n<\/tr>\n
\nchar [ ( n ) ] <\/td>\n | char[(n)], 1<=n<=2000; clob, n>2000<\/td>\n<\/tr>\n
\nvarchar [ ( n | max ) ] <\/td>\n | varchar2(n), 1<=n<=4000; clob (n>4000)<\/td>\n<\/tr>\n
\ntext<\/td>\n | clob<\/td>\n<\/tr>\n
\nnchar [ ( n ) ] <\/td>\n | nchar[(n)], 1<=n<=2000; nclob(n>2000)<\/td>\n<\/tr>\n
\nnvarchar [ ( n | max ) ]<\/td>\n | nvarchar2[(n)], 1<=n<=4000; nclob( n>4000 )<\/td>\n<\/tr>\n
\nntext<\/td>\n | nclob<\/td>\n<\/tr>\n
\nbinary [ ( n ) ]<\/td>\n | raw(1)(n was omitted); raw(n), 1<=n<=2000; blob(n>2000)<\/td>\n<\/tr>\n
\nvarbinary [ ( n | max) ] <\/td>\n | raw(1)(n was omitted); raw(n), 1<=n<=2000; blob(n>2000)<\/td>\n<\/tr>\n
\nimage<\/td>\n | blob<\/td>\n<\/tr>\n<\/table>\n<\/div>\n \n \nReference: \n1. Oracle datatypes<\/a> \n2. SQL Server datatypes<\/a><\/p>\n","protected":false},"excerpt":{"rendered":" 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 one of the series of articles 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\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,25,17],"tags":[23],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":5}},"yoast_head":"\nDatatypes translation between Oracle and SQL Server part 1: character, binary strings<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n