I've been given a task to convert a huge database in MS SQL Server to Oracle. The database has more than 150 tables with lots of constraints,defaults and relationships, that many stored procedures and triggers. Now I wonder 2 things:
Thanks in advance.
The CHAR data type can store a character string with the size from 1 to 2000 bytes. If you don't explicitly specify BYTE or CHAR followed the length , Oracle uses the BYTE by default. When you insert or update a fixed-length character string column, Oracle stores the characters as the fixed-length data.
Varchar2(10) uses the current value of NLS_LENGTH_SEMANTICS to determine the limit for the string. If this is byte, then it's 10 bytes. If it's char, then it's 10 characters. In multibyte character sets these can be different!
3) Another difference between char and byte is that char is a larger data type than a byte. The range of byte is between -128 to 127 but the range of char is from 0 to 65535 because a byte is a signed 8-bit data type and char is an unsigned 16-bit data type hence, its maximum value is 2 ^ 16 - 1 which is 65535.
VARCHAR2(20 BYTE) : Allows only the specified number of bytes to be stored in the column, regardless of how many characters this represents. VARCHAR2(20 CHAR) : Allows the specified number of characters to be stored in the column regardless of the number of bytes this equates to.
For 2: This will produce code to update all BYTE columns to CHAR
BEGIN
FOR x in (SELECT * FROM user_tab_columns WHERE data_type LIKE 'VARCHAR%' and CHAR_USED = 'B')
LOOP
DBMS_OUTPUT.PUT_LINE('ALTER TABLE '||x.table_name||' MODIFY '||x.column_name||' '||x.data_type||'('||x.data_length||' CHAR)');
END LOOP;
END;
/
I migrated MS SQL Server database to Informix with self made batch that used ADO.NET metadata to retrieve db structure. I did that because I couldn't find appropriate tool for this conversion. I wouldn't advise this approach with databases that can be migrated using exisitng tool.
So, in case of migrating to Oracle it is better to use some of existing tools like this:
http://www.oracle.com/technetwork/database/migration/sqlserver-095136.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With