oracle text index create and use


一、Install Text Index
1,The steps of context install on Oracle 10g.

1, create tablespace drsys
2, run @?/ctx/admin/catctx.sql ctxsys drsys temp01 nolock 
3, run @?/ctx/admin/defaults/drdefus.sql(-- run as ctxsys)
4, grant execute on ctxsys.ctx_ddl to public 

The steps of context uninstall (remove) on Oracle 10g.
-- run as sys 
@?/ctx/admin/catnoctx.sql 

2,The steps of context install on Oracle 9i.

1, create tablespace drsys
2, run ?/ctx/admin/dr0csys ctxsys drsys temp01
3, conn to ctxsys user
4, run ?/ctx/admin/dr0inst ?/ctx/lib/libctxx9.so
5, run ?/ctx/admin/defaults/drdefus.sql
6, grant execute on ctxsys.ctx_ddl to public; 

The steps of context uninstall (remove) on Oracle 9i.
-- run as ctxsys
$ORACLE_HOME/ctx/admin/dr0drop.sql
-- run as sys
$ORACLE_HOME/ctx/admin/dr0dsys.sql 

3,Verification of the context installation.
-- check dba_registry
col version format a14
col comp_name format a30
select COMP_NAME,VERSION,STATUS from dba_registry;

-- Create a sample table
create table  cr_ctxdemo (col1 number not null primary key, col2 varchar2(100));
insert into cr_ctxdemo values (1,'Oracle A B C');
commit;
create index idx_cr_ctxdemo_col2 on cr_ctxdemo(col2) indextype is ctxsys.context;
select col1 from cr_ctxdemo where contains(col2,'A or C') > 0;
set autot trace exp
select col1 from cr_ctxdemo where contains (col2,'A') > 0;
set autot off
drop table cr_ctxdemo; 

二、Use The Text Index
begin ctx_ddl.create_preference('smshis_fullidx','chinese_vgram_lexer'); end;


begin 
    Ctx_Ddl.Drop_Preference('smshis_fullidx'); 
END;
begin ctx_ddl.create_preference('smshis_fullidx','BASIC_LEXER'); end;

DROP INDEX smshis_text_idx_mobile;

Create Index smshis_text_idx_mobile On smshis(mobile) Indextype Is
Ctxsys.Context Parameters('lexer smshis_fullidx');

select mobile mobileNum,status,to_char(startTime,'yyyymmddhh24miss') sendTime,contents content, alarmType 
from smshis
where  mobile LIKE '%13911905263%';

select mobile mobileNum,status,to_char(startTime,'yyyymmddhh24miss') sendTime,contents content, alarmType 
from smshis
where contains (mobile,'13911905263',1) >0;

三、Question
1)It will not correct the result?
2)It must sync the text index by running job.
四、Reference Web Link
1)http://asktom.oracle.com/pls/apex/f?p=100:11:0::NO::P11_QUESTION_ID:2200894550208
2)http://forums.oracle.com/forums/thread.jspa?threadID=882001
3)http://www.oracle-base.com/articles/9i/FullTextIndexingUsingOracleText9i.php
4)http://blog.csdn.net/hunterdiary/archive/2009/04/02/4043099.aspx