1

私はカンマで値を区切ってとコンテキストインデックスは

create index myindex on mytable(description) indextype IS CTXSYS.CONTEXT parameters(lexer mylex);

記述欄が含まれている記述欄の構造以下

mytable(id number, name varchar2(100), department varchar2(100), description varchar2(100));

と作成されたコンテキストインデックスを持つテーブルがある特殊文字を含めるには私が行うとき以下の検索はOR検索を行います。

select * from mytable where contains(description,'aaron,lord')>0;

はアーロン又は主として記述欄を有する結果を与えます。

答えて

0

\または{...}からescape accumulate operatorsのいずれかを使用します。

サンプル・スキーマ

--drop table mytable; 

create table mytable(id number, 
name varchar2(100), 
department varchar2(100), 
description varchar2(100)); 

insert into mytable values(1, 'A', 'A', 'aaron,lord'); 
insert into mytable values(2, 'B', 'B', 'aaron'); 
insert into mytable values(3, 'C', 'C', 'lord'); 
commit; 

create index myindex on mytable(description) 
indextype IS CTXSYS.CONTEXT; 

が問題

デフォルトではコンマはaccumlate演算子として扱われ、それらはすべて「アーロン」または「領主」のいずれかを持っているので、4つのすべての行を返します。

select description from mytable where contains(description,'aaron,lord')>0; 

DESCRIPTION 
----------- 
aaron,lord 
aaron 
lord 
aaron lord 

ソリューションパート1 - 和を防ぎ、「アーロン」と「領主」を除外しますアキュムレータのエスケープエスケープコンマ

。私は実際のクエリがバインド変数を使用し、ハードコードされていないと仮定します。なぜなら、単純に文字列を変更するのではなく、REPLACEまたは||のいずれかを使用する理由です。

select description from mytable where contains(description, replace('aaron,lord', ',', '\,')) > 0; 
select description from mytable where contains(description, '{' || 'aaron,lord' || '}') > 0; 

DESCRIPTION 
----------- 
aaron,lord 
aaron lord 

ソリューション部2 - 今だけ一つの行が返される

drop index myindex; 

begin 
    ctx_ddl.create_preference('mylex', 'BASIC_LEXER'); 
    ctx_ddl.set_attribute('mylex', 'printjoins', ','); 
end; 
/

create index myindex on mytable(description) 
indextype IS CTXSYS.CONTEXT 
parameters ('LEXER mylex'); 

をprintjoinするカンマを追加。

select description from mytable where contains(description, replace('aaron,lord', ',', '\,')) > 0; 
select description from mytable where contains(description, '{' || 'aaron,lord' || '}') > 0; 

DESCRIPTION 
----------- 
aaron,lord 

しかし、結果はCONTAINSを避け、普通のSQL関数および条件を使用する方が良いでしょうかしらので、特定の取得しています。

+0

ありがとうございました。それは私のために働いた:) – Mahi

+0

私はこのケースを使用しました 'mytableからdescriptionを選択してください(description、 '{' || 'aaron、lord' || '}')> 0;'それは値aaron主人も。これを避ける方法を教えてください。 – Mahi

+0

@Mahi私の更新された答えを見てください。 –