-1

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.

serefbilge
  • 1,654
  • 4
  • 29
  • 55

3 Answers3

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
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