Using SQL*Loader to Load the Table
You can use SQL*Loader to load a table in batches.
Perform the following steps to load your table in batches with SQL*Loader:
-
Create the
CONTEXTindex.Index the HTML files by creating a
CONTEXTindex on the text column as follows. Because you are indexing HTML, this example uses theNULL_FILTERpreference type for no filtering and theHTML_SECTION_GROUPtype. If you index PDF, Microsoft Word, or other formatted documents, then use theCTXSYS.AUTO_FILTER(the default) as yourFILTERpreference.CREATE INDEX idx_docs ON docs(text) INDEXTYPE IS CTXSYS.CONTEXT PARAMETERS ('FILTER CTXSYS.NULL_FILTER SECTION GROUP CTXSYS.HTML_SECTION_GROUP');This example also uses the
HTML_SECTION_GROUPsection group, which is recommended for indexing HTML documents. UsingHTML_SECTION_GROUPenables you to search within specific HTML tags and eliminate unwanted markup, such as font information, from the index. -
Query your table with
CONTAINS.First, set the format of the
SELECTstatement’s output so that it is easily readable. Set the width of thetextcolumn to 40 characters:COLUMN text FORMAT a40;Next, query the table with the
SELECTstatement withCONTAINS.This query retrieves the document IDs that satisfy the query. The following query looks for all documents that contain the word France:SELECT SCORE(1), id, text FROM docs WHERE CONTAINS(text, 'France', 1) > 0; SCORE(1) ID TEXT ---------- ---------- ---------------------------------------- 4 3 <HTML>France is in Europe.</HTML> 4 2 <HTML>Paris is a city in France.</HTML> -
Present the document.
In a real-world application, you could present the selected document with query terms highlighted. Oracle Text enables you to mark up documents with the
CTX_DOCpackage.You can demonstrate HTML document markup with an anonymous PL/SQL block in SQL*Plus. However, in a real-world application, you could present the document in a browser.
This PL/SQL example uses the in-memory version of
CTX_DOC.MARKUPto highlight the word France in document 3. It allocates a temporaryCLOB(character large object data type) to store the markup text and reads it back to the standard output. TheCLOBis then deallocated before exiting:SET SERVEROUTPUT ON; DECLARE 2 mklob CLOB; 3 amt NUMBER := 40; 4 line VARCHAR2(80); 5 BEGIN 6 CTX_DOC.MARKUP('idx_docs','3','France', mklob); 7 DBMS_LOB.READ(mklob, amt, 1, line); 8 DBMS_OUTPUT.PUT_LINE('FIRST 40 CHARS ARE:'||line); 9 DBMS_LOB.FREETEMPORARY(mklob); 10 END; 11 / FIRST 40 CHARS ARE:<HTML><<<France>>> is in Europe.</HTML> PL/SQL procedure successfully completed. -
Synchronize the index after data manipulation.
When you create a
CONTEXTindex, you explicitly synchronize your index to update it with any inserts, updates, or deletions to the text table.Oracle Text enables you to do so with the
CTX_DDL.SYNC_INDEXprocedure.Add some rows to the
docstable:INSERT INTO docs VALUES(4, '<HTML>Los Angeles is a city in California.</HTML>'); INSERT INTO docs VALUES(5, '<HTML>Mexico City is big.</HTML>');Because the index is not synchronized, these new rows are not returned with a query on city:
SELECT SCORE(1), id, text FROM docs WHERE CONTAINS(text, 'city', 1) > 0; SCORE(1) ID TEXT ---------- ---------- -------------------------------------------------- 4 2 <HTML>Paris is a city in France.</HTML>Therefore, synchronize the index with 2 Mb of memory and rerun the query:
EXEC CTX_DDL.SYNC_INDEX('idx_docs', '2M'); PL/SQL procedure successfully completed. COLUMN text FORMAT a50; SELECT SCORE(1), id, text FROM docs WHERE CONTAINS(text, 'city', 1) > 0; SCORE(1) ID TEXT ---------- ---------- -------------------------------------------------- 4 5 <HTML>Mexico City is big.</HTML> 4 4 <HTML>Los Angeles is a city in California.</HTML> 4 2 <HTML>Paris is a city in France.</HTML>See Also: “Building the PSP Web Application” for an example of how to use SQL*Loader to load a text table from a data file