Oracle text(全文檢索) 可以把任何文檔和文件編入索引,從而是訪問更快,更容易檢索相關的信息
1.檢查數據庫是否具有全文檢索功能(這是針對已經建成使用的數據庫)
查看用戶中是否存在ctxsys用戶,查詢角色裏是否存在ctxapp角色。以上兩個中的1個不滿足(不存在),則說明沒有裝過全文檢索功能。
使用contains函數的時候,若沒有全文檢索則會報錯的。
1.
--使用如下腳本。
SQL> connect SYS/password@tns_ as SYSDBA
SQL> spool text_install.txt
SQL> @?/ctx/admin/catctx.sql CTXSYS SYSAUX TEMP NOLOCK
--腳本中各個參數含義:
CTXSYS - is the ctxsys user password
SYSAUX - is the default tablespace for ctxsys
TEMP - is the temporary tablespace for ctxsys
LOCK|NOLOCK - ctxsys user account will be locked or not
2. The next step is to install appropriatelanguage-specific default preferences.
--指定默認的安裝語言
無此步驟,後續新建索引這裏將報錯
如此錯誤DRG-10700: preference does not exist: CTXSYS.DEFAULT_WORDLIST
--如果使用US作爲默認語言,執行drdefus.sql.
SQL> connect CTXSYS/password@tns_alias
SQL> @?/ctx/admin/defaults/drdefus.sql
SQL> spool off
exec ctx_ddl.create_preference ('chinalexer', 'chinese_lexer');
4、建立全文索引
create index YU_TEST_INDEX on YU_TEST(name) indextype is CTXSYS.CONTEXT parameters('lexer chinalexer');
這句話的意思就是,在YU_TEST_INDEX表中的name字段上創建索引,索引類系那個爲context類型,該索引用到的分析器爲前面定義的my_lexer,該索引用到的過濾詞組爲前面定義得my_stoplist。
5、使用索引
select * from YU_TEST where contains(name,'重慶')>0;
exec ctx_ddl.sync_index('yu_test_index')
exec ctx_ddl.optimize_index('yu_test_index','full')