I have an sql server script which inserts known fixed guid values into a table. It looks like:
INSERT INTO MyTable (ID) VALUES ('BBD098BF-58F0-4A84-90C2-F806D6D06061')
Note that guid is in human-readable form. Since ID is uniqueidentifier sql server understands how to convert a string to guid data type.
I need to make the same script for Oracle, ID is of RAW(16) type. Taking the script directly doesn’t work because Oracle interprets a string just like a binary, it should be some “other” string, a string representation of a correct binary chunk.
Does anyone knows a way to convert human-readable sql server string to a string required by Oracle?
So far I can only think about saving a guid to Oracle in .net code, for example, and than making a select in oracle script to get a string. But this is crazy.
Thanks!
Advertisement
Answer
According to this link
Sqlserver reverses the 3 first sections so you need to do:
hextoraw(substr(guid,7,2)|| substr(guid,5,2)|| substr(guid,3,2)|| substr(guid,1,2)|| substr(guid,12,2)|| substr(guid,10,2)|| substr(guid,17,2)|| substr(guid,15,2)|| substr(guid,20,4)|| substr(guid,25,12) )
(guid is like ‘BBD098BF-58F0-4A84-90C2-F806D6D06061’)