Bug #28485 Size of VARCHAR for MySQL is specified in charater length, for Oracle in bytes
Submitted: 17 May 2007 4:07 Modified: 29 Mar 2012 3:07
Reporter: Raymond DeRoo Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Workbench Severity:S3 (Non-critical)
Version:1.1.16 OS:Any
Assigned to: CPU Architecture:Any

[17 May 2007 4:07] Raymond DeRoo
Description:
Issue with transition of VARCHAR Oracle type to MySQL UTF-8 length for VARCHAR. Oracle used Unicode UTF-8 (AL32UTF8) as the database character set. Let us say the variable x was declared as CHAR(3), which resulted in an allocation of three bytes. When the single-byte value a was assigned to x, the other two bytes were padded with spaces (a space is also a single byte), and thus the resulting string was three characters long. When the two-byte character was assigned to x, only one byte remained to be padded with a single space. The result? A two-character-long string that happened to be using three bytes of storage. In our case (migrating from Oracle to MySQL), Oracle defines it's VARCHAR length in bytes where as MySQL defines the length in Char. When the migration script is created a one for one mapping occurs which is incorrect. Also the the keyword BINARY is unnecessarily added.

How to repeat:
Example migration error:

Oracle Table Description:

>>>

SQL> desc class_of_service_parameter_tbl;

Name Null? Type

----------------------------------------- -------- ----------------------------

CLASS_OF_SERVICE_KEY NOT NULL VARCHAR2(256)
PARAMETER_KEY NOT NULL VARCHAR2(256)
PARAMETER_VALUE VARCHAR2(256)
>>>

MySQL Migration Tool Script:

>>>

CREATE TABLE `agw`.`class_of_service_parameter_tbl` (
`class_of_service_key` VARCHAR(256) BINARY NOT NULL,
`parameter_key` VARCHAR(256) BINARY NOT NULL,
`parameter_value` VARCHAR(256) BINARY NULL,
PRIMARY KEY (`class_of_service_key`, `parameter_key`),
INDEX `i1_class_of_service_parameter` (`class_of_service_key`(256)),
INDEX `i2_class_of_service_parameter` (`parameter_key`(256))
) ENGINE = INNODB

CHARACTER SET utf8 COLLATE utf8_general_ci;

>>>
[6 Feb 2009 12:31] Susanne Ebrecht
You will find varchar(n) with n given bytes in lots of other RDBMS too. Afair n in bytes is given in SQL Standard. We should find a solution here. 

Verified as described.
[12 Feb 2009 13:54] Susanne Ebrecht
The workaround here is to change length of VARCHAR manually.