Dealing with GUID values in Oracle Lite

In Oracle Lite, the RAW(16) binary data type is typically used to store a GUID value. When you try to retrieve data from a column defined as RAW and apply the to_char() function to it, the data retrieved will be returned in the form of a hexadecimal string. The following is an example of such an SQL statement:

SELECT TO_CHAR(AccountGUID) FROM Accounts

The retrieved data cannot be directly read into a System.Guid object. The hexadecimal string must first be converted into a byte array, and then fed into the System.Guid (byte()) constructor to obtain a System.Guid object. Likewise, if you wanted to write to a RAW column in the database, you have to first convert your System.Guid object into a byte array and then into a hexadecimal string.

We will not go into the details of converting between hexadecimal strings and byte arrays. (These functions GUIDToHex() and HexToGUID() are provided in this book's companion source code.)

The GUIDToNative() and NativeToGUID() implementations will need to call the conversion functions in the following fashion:

public object GUIDToNative(System.Guid AccountGUID) {

return GUIDToHex(AccountGUID);

public System.Guid NativeToGUID(object AccountGUID) {

return HexToGUID(AccountGUID);

Was this article helpful?

0 0

Post a comment