Is it possible to check a string in C#, whether it is string version of oracle raw(16) type data? For example, "5D03D47919127C4DBBD58AF69BF4D81A" is string version of a raw(16) type data.
Asked
Active
Viewed 851 times
-1
-
raw is binary data, if im not mistaken. – Woot4Moo May 13 '13 at 14:38
-
are you trying to persist or retrieve or both? – Woot4Moo May 13 '13 at 14:45
-
http://stackoverflow.com/questions/7289734/convert-from-oracles-raw16-to-nets-guid – I4V May 13 '13 at 14:46
-
I want to check a string whether it is in raw16 format. – serefbilge May 13 '13 at 14:47
-
@I4V, I can generate it; I'm not asking how to generate. – serefbilge May 13 '13 at 14:49
-
there really isn't any formatting that you do. Raw is just bytes Oracle as no way of knowing what the format is. – Woot4Moo May 13 '13 at 14:55
-
1Are you actually asking about **hexadecimal**? – SLaks May 13 '13 at 15:01
-
I don't know what "Bitconver.ToString()" does. But, it sounds true, if "5D03D47919127C4DBBD58AF69BF4D81A" is in hexadecimal format. – serefbilge May 13 '13 at 15:09
3 Answers
0
When you retrieve the raw (bytes) from Oracle you need to do something like this:
var str = System.Text.Encoding.Default.GetString(rawColumnData);
it is up to you to ensure the correct encoding is used.

Woot4Moo
- 23,987
- 16
- 94
- 151
-
-
-
I want to check a confirmation code in type of raw(16), before checking if it exists in database. By this way, if it is not in true format, I would not need to check it from database. – serefbilge May 13 '13 at 15:02
0
I am not sure about what you're really asking. Is it something like this?
string hexstr = "5D03D47919127C4DBBD58AF69BF4D81A";
var allowChars = new HashSet<char>("0123456789ABCDEF");
bool isAHexString = hexstr.All(allowChars.Contains) && hexstr.Length == 32;

EZI
- 15,209
- 2
- 27
- 33
0
Not sure your use case, but I prefer storing 32 hex as 32 hex (varchar2(32) rather than as raw(16)). Just avoids the constant hextoraw/rawtohex conversions, and easier for other apps to work with as well.
Anyway, on the Oracle side, you can try inserting it into your raw field (converting on the fly), and catch any ORA-01465 exceptions (invalid hex number):
insert into my_table(my_raw_field) values (hextoraw(some_hex_variable));

tbone
- 15,107
- 3
- 33
- 40
-
I want to check it before going to database. It will be a pre-checking mechanism. – serefbilge May 13 '13 at 18:02