Google Answers Logo
View Question
 
Q: How to search for a word in content of XML File stored in a clob fiela ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: How to search for a word in content of XML File stored in a clob fiela
Category: Computers
Asked by: ramxml-ga
List Price: $20.00
Posted: 09 Aug 2002 10:29 PDT
Expires: 08 Sep 2002 10:29 PDT
Question ID: 52648
I have a clob field in an Oracle Table.
Table stores Fileid in a column, file name in a column and Total file
in a column.
Total file column is a clob field.
I will store FoleID, XML filename and Complete xmlfile in the
respective columns
After that If I need to search, which file has the given string.

Example
Table is Stg_IB_Msg
File_ID	   File_Name	File_Text (Clob Field)



If I have a table like this , Is it possible to search like this?

Select File_name from Stg_IB_Msg where contains(File_Text,’121212’) >
0

Purpose of thi sis to return the file name, which contains the word
“121212 in that file

I tried this in Oracle. But giving error.
Is there any way to search the clob for pertcular word?

Request for Question Clarification by joseleon-ga on 09 Aug 2002 12:17 PDT
Hello:
  Your question seems pretty easy, but I'm sure you have tried what
I'm going to tell you, so I don't post it as an answer, take a look to
the following links:

Oracle9i SQL Reference
http://download-west.oracle.com/otndoc/oracle9i/901_doc/server.901/a90125/toc.htm

Oracle SQL LIKE Conditions 
http://download-west.oracle.com/otndoc/oracle9i/901_doc/server.901/a90125/conditions9.htm#1002951

Your query will be something like:

SELECT FILE_NAME FROM STG_IB_MSG WHERE FILE_TEXT LIKE '%121212%'

and this will return the rows which file text contains the word 121212
somewhere.

I don't know if this will work on your system with CLOB fields, you
can try to use another types like BLOB, take a look at this page:

Oracle Built-in Datatypes
http://download-west.oracle.com/otndoc/oracle9i/901_doc/server.901/a90125/sql_elements2.htm#54201

Please, if this solves your question, let me answer it.

Regards.

Clarification of Question by ramxml-ga on 09 Aug 2002 13:02 PDT
Hi joseleon-ga ,
Thanks for your response.
But if I use like ,Bcoz of a clob data type I will end up with 
ORA-00932: inconsistent datatypes

I'm not sure why, But my manger clearly specified not to use like and percentage.
ThankYou for your response. is there any way to deal with it?

Request for Question Clarification by iaint-ga on 10 Aug 2002 02:10 PDT
Hi ramxml

Could you let me know precisely which version of Oracle you are using:
is it 8i or 9i, and if 9i is it release 1 (9.0.1) or release 2
(9.2.0)? Oracle are still developing and improving the XML support
within their core database products and the techniques required to do
what you want will depend very much on the precise version of Oracle.

One further question: are you storing pure XML data in the File_Text
field? If so, you may want to consider using the XMLTYPE data type
rather than ordinary CLOB: XMLTYPE is a derivation of CLOB but
provides some extra functionality for accessing and storing XML data.

Regards
iaint-ga

Clarification of Question by ramxml-ga on 13 Aug 2002 14:19 PDT
hi iaint
Thank You very much for your response. Bcoz of tight schedules,Till
today I havent see your message.  I'm using oracle 8i version.  I will
check for that xml datatype in 8i.  As of today we are storing the
whole xml file into a clob field.
ThankYou verymuch for your time. I Appriciate it
Answer  
Subject: Re: How to search for a word in content of XML File stored in a clob fiela
Answered By: iaint-ga on 14 Aug 2002 02:02 PDT
Rated:5 out of 5 stars
 
Hi ramxml

Thank you for getting back to me about what version of Oracle you're
using, as this makes a considerable difference in how you might
successfully query your XML data stored in a CLOB field. Most of the
following information has been summarised from the book "Building
Oracle XML Applications" by Steve Muench, O'Reilly 2000, ISBN
1-56592-691-9. I can wholeheartedly recommend this book to solve many
of your XML/Oracle questions.

http://www.oreilly.com/catalog/orxmlapp/

As you are using Oracle 8i, then you have to associate a context with
your CLOB data if you want to be able to search its contents. This is
achieved using the Oracle interMedia text component (interMedia is the
new name for the technologies based on the old Oracle ConText
product). To quote from the O'Reilly book, p502-503:

"interMedia Text ... enables searching XML documents, document
fragments, and other document content. While the interMedia extensions
are technically a separate product, they are included on the Oracle8i
CD and can be installed and used at no additional cost." A more
detailed explanation of interMedia for Oracle 8i -- including
installation instructions -- is available at:
http://www.orafaq.com/faqctx.htm

I would therefore say that before you go any further, you must find
out whether or not you have the interMedia extensions installed, and
if not you must ensure that your DBA installs them as soon as
possible.

Once interMedia text is installed and running, you can then fairly
simply perform the searches you require (in fact, you can go much
further than you requested in your question and use XPath-like queries
to search subsections of your XML documents). The "magic bullet" which
will let you do all this is the SQL CONTAINS() function. In your case,
you would simply require the following query:

   SELECT File_Name
     FROM Stg_IB_Msg
    WHERE CONTAINS( File_Text, '121212' ) > 0;

A couple of important points to note about this query: firstly as
stated above it will only work if you interMedia running. Secondly,
it's not necessary to add '%' wild-card markers to the text, the
CONTAINS() function searches for substrings by default. Finally note
that the CONTAINS() function allocates a "score" (of 0-100) to the
returned data, so to make any useful sense of its return value the '>
0' expression must be specified.

For the official syntax of the CONTAINS() function, and a couple of
examples, you can consult the online Oracle documentation at:
http://doc.oracle.com/cd_a87860/doc/inter.817/a77063/csql4.htm#21732

There is a lot (an AWFUL lot) more information about the interMedia
text technologies at:
http://otn.oracle.com/products/text/x/Tech_Overviews/imt_815.html

Finally, if your company and budget allows it, can I seriously
recommend you consider upgrading to Oracle 9i -- in particular 9i
Version 2 -- if you are going to be creating XML-aware applications
using Oracle. In the few short years since XML support first appeared
in the Oracle database the functionality has improved by leaps and
bounds. In 9i version 2, for example, you can run full XPath
expressions on stored XML to query or extract subsections of the XML
data, and there is no absolute requirement to have the interMedia
component running.


I hope the above enables you to continue with your development
project; if any of the above doesn't make sense to you please ask for
further clarification.

Regards
iaint-ga


Search methods:

As mentioned, much of the above knowledge came from my own personal
copy of the O'Reilly book "Building Oracle XML Applications". To find
the websites listing details of the SQL CONTAINS() function I did a
Google search for:

oracle 8i intermedia contains
://www.google.co.uk/?q=oracle+8i+intermedia+contains
oracle 8i "where contains"
://www.google.co.uk/?q=oracle+8i+%22where+contains%22

To find the syntax defintion for the CONTAINS() function I searched
within the 8i documentation at Oracle's online document repository at:
http://doc.oracle.com/

Request for Answer Clarification by ramxml-ga on 14 Aug 2002 11:42 PDT
hi iaint 
ThankYou very much for your detailed answer.  Basicaly my role is
restricted for coding. In this kind of environment, I have already
asked DBA to do it, But I dont think I will get much help from him. 
This is the problem everywhere in such big companies.  May be I will
inform to my manager all this.
I really appreciate your detailed answer.  I can understand how much
time you spent on this,  Thanks for your amswer.  I will let my
manager knows all this and afterwards its up to DBA.
I'm not sure how this payment works. But you please claim the price
that I have offered. To be frank it is less when I consider th etime
you spent.
ThankYou verymuch.

Clarification of Answer by iaint-ga on 19 Aug 2002 03:49 PDT
Hi ramxml

I hope that the answer given has helped you out and let you continue
with your development work. Thank you very much for your kind
comments: if you wish to give my answer a rating then please feel free
to do so.

Regards
iaint-ga
ramxml-ga rated this answer:5 out of 5 stars

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy