oracle全文檢索

2021-07-05 12:07:23 字數 1500 閱讀 1092

先建立個表

可見content是blob型的,本文就是給content欄位全文檢索(注:該錶名為sycontent)

--建立全文檢索lexer  建立全文索引時,你用的使用者必須要有ctx_dll許可權,如果沒有再,在該使用者的超級管理使用者下的sysdba登入執行

grant execute on ctx_ddl to myusers; --其中myusers是你的登入使用者

--建立全文索引

--1begin

ctx_ddl.create_preference('knowlexer','chinese_vgram_lexer');--這個效率不好但是查詢比較精確

end;

--2begin

ctx_ddl.create_preference('knowlexer1','chinese_lexer');--這個查詢不太精確,但是查詢會快

end;

--在這個表的content欄位上加上全文檢索的lexer

create index content_index on sycontent(content) indextype is ctxsys.context parameters ('lexer knowlexer')

--此時你在資料庫中給sycontent表,加上一條資料,用全文檢索的語句查詢

--比如,你新加的資料中content欄位中為 '你好我是小李',當你執行下邊這條語句時並沒有,查到資料

select * from sycontent where contains(content,'你好')>0

--因為你先建了索引後填的資料,這些新的資料沒有更新所有,要給這些新的資料也加上索引所以要執行,下邊這兩條語句

begin

ctx_ddl.sync_index('content_index');

ctx_ddl.optimize_index('content_index','full');

end;

--執行之後再執行

select * from sycontent where contains(content,'你好')>0 ---就會有結果

--那麼在實際應用中,可以把這個語句放在儲存過程中來執行,

create or replace procedure p_lexer_content is

begin

ctx_ddl.sync_index('content_index');

ctx_ddl.optimize_index('content_index','full');

end;

--然後再再資料庫中建乙個job,根據需要,定時呼叫這個儲存過程,那麼新新增的資料就會定時更新上索引了(怎樣建job不再說明)

oracle全文檢索

測試環境oracle11g begin ctx ddl.create preference test lexer chinese vgram lexer ctx ddl.create preference sms address lexer chinese lexer end create inde...

oracle全文檢索(oracle text)記錄

size large 1.全文檢索和普通檢索的區別 不使用oracle text功能,當然也有很多方法可以在oracle資料庫中搜尋文字,比如instr函式和like操作 select from mytext where instr thetext,oracle 0 select from myte...

什麼叫全文檢索 全文檢索概念

全文檢索是指計算機索引程式通過掃瞄文章中的每乙個詞,對每乙個詞建立乙個索引,指明該詞在文章中出現的次數和位置,當使用者查詢時,檢索程式就根據事先建立的索引進行查詢,並將查詢的結果反饋給使用者的檢索方式。這個過程類似於通過字典中的檢索字表查字的過程。全文檢索的方法主要分為按字檢索和按詞檢索兩種。按字檢...