tags:

views:

39

answers:

2

Hi
I have a column of RAW type in my database. How can I use it in where clause?
i.e to get only values with third byte equal to 4.
this does not work:

SELECT v from T where v[3]=4
+5  A: 

Hi Roman,

use the functions of the UTL_RAW package to interact with raws, for example:

SQL> create table test (a raw(16));

Table created

SQL> insert into test values ('FF00FF00FF');

1 row inserted

SQL> select * from test where utl_raw.substr(a, 3, 1) = 'FF';

A
--------------------------------
FF00FF00FF
Vincent Malgrat
A: 

One can also use REGEXP_LIKE function to select rows with RAW datatype:

select * from test where REGEXP_LIKE(a,'^....04.*')";

In my use case this method is a little faster than utl_raw.substr.

Roman