开发者

oracle raw datatype in where clause

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


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


in Oracle : you can use HEXTORAW function

  • select * from TBLTest01 where (BINCOL=hextoraw('f0f0f3') )

it is in other databases in another way. for example in DB2 :

  • select * from TBLTest01 where BINCOL=BINARY(x'F0F0F3')


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜