Convert Raw[16](Guid) in Oracle to uniqueidentifier in SQL Server by SSMA
我已经解决了我需要将数据从
在
但是,当SSMA开始转换数据时,它将返回此异常:
The given value of type Byte[] from the data source cannot be
converted to type uniqueidentifier of the specified target column.
1 2 3 4 5 6 7 8 9 | DECLARE @uniqORAconvMS varchar(32) = '5cf5d1b5db12d38067affb261d9619dc' SELECT left(@uniqORAconvMS,8) + '-' + SUBSTRING(@uniqORAconvMS,9,4) + '-' + SUBSTRING(@uniqORAconvMS,13,4) + '-' + SUBSTRING(@uniqORAconvMS,17,4) + '-' + RIGHT(@uniqORAconvMS,12) -- xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -- 5cf5d1b5-db12-d380-67af-fb261d9619dc -- With TRY_CONVERT to check valid uniqueidentifier SELECT TRY_CONVERT (UNIQUEIDENTIFIER, LEFT(@uniqORAconvMS,8) + '-' + SUBSTRING(@uniqORAconvMS,9,4) + '-' + SUBSTRING(@uniqORAconvMS,13,4) + '-' + SUBSTRING(@uniqORAconvMS,17,4) + '-' + RIGHT(@uniqORAconvMS,12)) |
ORACLE SYS_GUID是RAW(16),它是32个字符的十六进制表示形式。
等效的SQL Server数据类型Uniqueidentifier是16字节的二进制值,它是36个字符的表示形式。
SQL Server唯一标识符
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, in which each x is a hexadecimal
digit in the range 0-9 or a-f. For example,
6F9619FF-8B86-D011-B42D-00C04FC964FF is a valid uniqueidentifier value
您可以想到以下选项:
-
我建议您在类型映射中使用VARCHAR(32)表示SQLServer中的相应ORACLE GUID。
-
您可以为目标列设置NEWID()的默认值,在加载数据时将分配值
-
将目标数据类型设置为
VARCHAR(36) ,一旦完成迁移,就可以开始将NEWID()用于将来的值。 由于GUID将是唯一的,因此您不会遇到问题。