where 子句中的 oracle 原始数据类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3101363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:53:49  来源:igfitidea点击:

oracle raw datatype in where clause

sqloracle

提问by Roman

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:

我的数据库中有一个 RAW 类型的列。如何在 where 子句中使用它?
即只获取第三个字节等于 4 的值。
这不起作用:

SELECT v from T where v[3]=4

回答by Vincent Malgrat

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

使用UTL_RAW包的函数与raws交互,例如:

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

回答by afshar

in Oracle: you can use HEXTORAWfunction

Oracle 中:您可以使用HEXTORAW函数

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

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

它以另一种方式存在于其他数据库中。例如在DB2 中

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

回答by Roman

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

还可以使用 REGEXP_LIKE 函数来选择具有 RAW 数据类型的行:

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

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

在我的用例中,此方法比 utl_raw.substr 快一点。