Sql 如何使用oracle contains搜索具有特殊字符的整个单词?
我的表中有一列short_desc,它是上下文索引的 当我像下面这样搜索时Sql 如何使用oracle contains搜索具有特殊字符的整个单词?,sql,oracle,Sql,Oracle,我的表中有一列short_desc,它是上下文索引的 当我像下面这样搜索时 select * from table1 where CONTAINS (short_desc,'{product\_id}') > 0 我得到的结果是 abc产品标识 abc产品id 转义字符的行为类似于OR,查询将搜索“product\u id”或“product id” 我怎样才能只搜索“产品id”这个词 提前感谢您可以试试这个 select * from table1 where CONTAINS (
select * from table1 where CONTAINS (short_desc,'{product\_id}') > 0
我得到的结果是
abc产品标识
abc产品id
转义字符的行为类似于OR,查询将搜索“product\u id”或“product id”
我怎样才能只搜索“产品id”这个词
提前感谢您可以试试这个
select * from table1 where CONTAINS (short_desc,'{product'||'\_id}') > 0
根据标准,非字母字符被视为空白(因此product$id和product_id都被视为“product id”)
这一行为在一次会议上得到了证实。在“产品”和“id”之间放置哪个非字母符号无关紧要
要改变这一点,必须在上下文索引使用的lexer中
我无法在SQLFIDLE中演示这一点,因为此处限制了对ctx_ddl
包的访问,但此代码必须完成以下任务:
create table table1(short_desc varchar2(200))
/
-- Add lexer definition and set '_' as "printjoin"
begin
ctx_ddl.create_preference('mylex', 'BASIC_LEXER');
ctx_ddl.set_attribute('mylex', 'printjoins', '_');
end;
/
-- Specify new lexer definition while creating index
create index table1_ctx_index on table12(short_desc)
indextype is ctxsys.context
parameters ( 'LEXER mylex' )
/
insert into table1(short_desc) values('1 product id 2')
/
insert into table1(short_desc) values('3 product_id 4')
/
insert into table1(short_desc) values('5 product#id 6')
/
insert into table1(short_desc) values('7 productXid 8')
/
insert into table1(short_desc) values('9 product-id 10')
/
alter index table1_ctx_index rebuild
/
请尝试从表1中选择*,其中我要使用的短描述(如“%product\u id%”)包含。类似于工作…但包含需要300毫秒。大概需要14秒。所以我想用contains,你们两个都用吗?
包含使用索引的,以及类似的来缩小结果范围。这是一个遗留应用程序。我真的没什么变化。我只是好奇为什么它不起作用,以特定的方式更改搜索词(如正确转义字符等)将解决问题。它会给出相同的结果。尝试使用REGEXP_,如…我认为它会起作用…我现在没有sql,否则会提供准确的查询速度会慢很多吗?