Oracle full-text search

Source: Internet
Author: User

Using like '%', Oracle performs a full table scan, which consumes a considerable amount of system resources. This allows you to use full-text retrieval of oracle to increase the query speed.

  1. SQL>Select*FromV $ versionWhereRownum = 1;
  2. BANNER
  3. ----------------------------------------------------------------
  4. OracleDatabase10g Enterprise Edition Release 10.2.0.1.0-Prod
  5. SQL>Create TableT (textVarchar(4000 ));
  6. The table has been created.
  7. SQL>Insert IntoTValues('You love her so much, why don't you leave her');
  8. One row has been created.
  9. SQL>BeginCtx_ddl.create_preference ('Club _ lexer','Chinese _ vgram_lexer');End
  10. 2/
  11. The PL/SQL process is successfully completed.
  12. SQL>Create IndexIdx_t_textOnT (text) indextypeIs
  13. 2 ctxsys. context parameters ('Lexer club_lexer');
  14. The index has been created.
  15. SQL>Select Count(*)FromTWhere Contains(Text,'Who')> 0;
  16. Select Count(*)FromTWhere Contains(Text,'Who')> 0
  17. *
  18. Row 3 has an error:
  19. ORA-29902: An error occurred while executing the ODCIIndexStart () Routine
  20. ORA-20000: Oracle Text error:
  21. DRG-10817:CONTAINSA phrase in which a search term contains a disabled word or a disabled word: What
  22. SQL>Select Count(*)FromTWhere Contains(Text,'Who')> 0;
  23. COUNT(*)
  24. ----------
  25. 1
  26. SQL>Select Count(*)FromTWhere Contains(Text,'Ta')> 0;
  27. COUNT(*)
  28. ----------
  29. 1
  30. SQL>Select Count(*)FromTWhere Contains(Text,'Then')> 0;
  31. COUNT(*)
  32. ----------
  33. 1

Regularly synchronize and optimize Indexes
  1. SQL>Create Or Replace ProcedureHsp_sync_indexAs
  2. 2Begin
  3. 3 ctx_ddl.sync_index ('Idx _ t_text');
  4. 4End;
  5. 5/
  6. The process has been created.
  7. SQL>-- Regularly synchronize Indexes
  8. SQL> VARIABLE jobno number;
  9. SQL>BEGIN
  10. 2 DBMS_JOB.SUBMIT (: jobno,'Children _ sync_index ();',
  11. 3 SYSDATE,'Sysdate + (1/24/4 )');
  12. 4Commit;
  13. 5END;
  14. 6/
  15. The PL/SQL process is successfully completed.
  16. SQL>Create Or Replace ProcedureHsp_optimize_indexAs
  17. 2Begin
  18. 3 ctx_ddl.optimize_index ('Idx _ t_text','Full');
  19. 4End;
  20. 5/
  21. The process has been created.
  22. SQL>-- Regularly optimize Indexes
  23. SQL> VARIABLE jobno number;
  24. SQL>BEGIN
  25. 2 DBMS_JOB.SUBMIT (: jobno,'Heat _ optimize_index ();',
  26. 3 SYSDATE,'Sysdate + 1');
  27. 4Commit;
  28. 5END;
  29. 6/
  30. The PL/SQL process is successfully completed.
Before creating a synchronization and optimized storage process, www.bkjia.com should use the sys user to grant permissions to evan users: grant execute on ctx_ddl to evan;
Otherwise, the following message will be reported:
SQL> create or replace procedure hsp_sync_index
2 begin
3 ctx_ddl.sync_index ('idx _ t_text ');
4 end;
5/
Warning: the creation process has a compilation error.
SQL> show errors
PROCEDURE heat _ sync_index error:
LINE/COL ERROR
-------------------------------------------------------------------------
3/5 PL/SQL: Statement ignored
3/5 PLS-00201: The identifier 'ctx _ ddler' must be declared'
In addition, pay special attention to forbidden words.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.