How to insert an existing GUID in an Oracle RAW (16) field in a script

I have a sql script server that inserts known fixed guid values ​​into a table. It looks like this:

INSERT INTO MyTable (ID) VALUES ('BBD098BF-58F0-4A84-90C2-F806D6D06061') 

Please note that guid is in readable form. Since the sql server uniqueidentifier identifier understands how to convert a string to a guid data type.

I need to make the same script for Oracle, the ID is of type RAW (16). Taking a script directly does not work, because Oracle interprets a string in the same way as a binary, it must be some kind of "other" string, a string representation of the correct binary fragment.

Does anyone know a way to convert a readable sql server string to a string required by Oracle?

So far, I can only think about saving the manual for Oracle in .net code, for example, and making a choice in an oracle script to get a string. But this is crazy.

Thanks!

+4
source share
1 answer

According to this link, Sqlserver cancels the first 3 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")

+4
source

Source: https://habr.com/ru/post/1411295/


All Articles