oracle全文索引

來源:互聯網
上載者:User

標籤:

  1.檢查資料庫是否具有全文檢索索引功能(這是針對已經建成使用的資料庫)

        查看使用者中是否存在ctxsys使用者,查詢角色裡是否存在ctxapp角色。以上兩個中的1個不滿足(不存在),則說明沒有裝過全文檢索索引功能。

      使用contains函數的時候,若沒有全文檢索索引則會報錯的。

    2.若沒有,則需要手動建立,先建立全文檢索索引要使用的空間

             sqlplus / as sysdba  --進入控制台

            create tablespace Idx_ctxsys datafile ‘/oradata/sg186fx/ctxsys01.dbf size 10240M autoextend on next 32M maxsize 20480M;--建立全文檢索索引使用的資料表空間

    3.建立全文檢索索引使用的使用者和角色及相應的包,則需要執行oracle內建的一個指令碼:cd $ORACLE_HOME/ctx/admin/catctx.sql

         還是在sqlplus中執行:

                @?/ctx/admin/catctx.sql ctxsys Idx_ctxsys temp nolock

在執行這個指令碼的時候,輸入了幾個參數,第一個參數ctxsys為ctxsys使用者的密碼

                                                     第二個參數Idx_ctxsys為ctxsys使用者要使用的資料表空間

                                                      第三個參數temp為ctxsys使用者使用的暫存資料表空間

                                                    第四個參數nolock為ctxsys使用者處於解鎖狀態。

   4.建立完成後,要登入ctxsys使用者

             connect ctxsys/ctxsys

    執行以下指令碼:@?/ctx/admin/defaults/drdefus.sql(這是個很重要的指令碼,後面建立索引會使用該指令碼建立的資訊)

 5.建立全文索引文法分析器

               先要明確使用全文索引的使用者,我要使用全文索引的是sgpm使用者

       因此,grant execute on ctxsys.ctx_ddl to sgpm with grant option;

      connect sgpm/sgpm

      設定文法分析器:exec ctx_ddl.drop_preference(‘chinalexer‘);

                             exec ctx_ddl.create_preference(‘chinalexer‘,‘chinese_lexer‘);

       設定詞法屬性:exec ctx_ddl.drop_preference(‘idx_c_store‘);

                           begin

                                 ctx_ddl.create_preference(‘idx_c_store‘,‘BASIC_STORAGE‘);

                                  ctx_ddl.set_attribut(‘idx_c_store‘,‘I_TABLE_CLAUSE‘,‘tablespaces  Idx_ctxsy‘);

                                  ctx_ddl.set_attribute(‘idx_c_store‘,‘I_INDEX_CLAUSE‘,‘tablespace  Idx_ctxsy compress 2‘);

                          end;

                         /

     6.建立索引

           create index sgpm.idx_c_cons_name on sgpm.c_cons(cons_name) indextype is ctxsys.context parameters(‘lexer chinalexer storage idx_c_store‘);

     7.同步索引

         variable jobno number;

         begin

             dbms_job.submit(:jobno,‘pkg_sp_tools.p_cont_sys_index();‘,sysdate,‘trunc(sysdate)+19/24+1‘);  --執行的是個人化方法。

         end;

        /

   普通的就是用: exec ctx_ddl.sync_index(‘idx_c_cons_name‘);

 到此,全文檢索索引建立成功,contains函數就可以正常使用了。

注意:建立的過程中會出現ORA-29879:cannot create multiple domain index on a column listusing same indextype ,這說明在其他使用者下已經建立了該索引。

oracle全文索引

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.