\
または{...}
から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関数および条件を使用する方が良いでしょうかしらので、特定の取得しています。
ありがとうございました。それは私のために働いた:) – Mahi
私はこのケースを使用しました 'mytableからdescriptionを選択してください(description、 '{' || 'aaron、lord' || '}')> 0;'それは値aaron主人も。これを避ける方法を教えてください。 – Mahi
@Mahi私の更新された答えを見てください。 –