Oracle Enterprise Edition 11.1.0.7 64 bit (Jan 2012 CPU applied)
Windows 2003 64 bit
We have an XML file with the following sample format.
<?xml version="1.0"?>
<HR>
<EMP>
<FNAME>JOHN</FNAME>
<LNAME>DOE</LNAME>
<COMMENT>Comment with less than 4000 characters</COMMENT>
</EMP>
<EMP>
<FNAME>JANE</FNAME>
<LNAME>DOE</LNAME>
<COMMENT>Comment with more than 4000 characters</COMMENT>
</EMP>
</HR>
The query below
(full disclosure: which I took from odie_63's response in
1083104 and added the CURSOR_SHARING_EXACT hint on the top)
works when the contents of the <Comment> tag are smaller than 4000 characters. If it is more than 4000 I get
ORA-01706: user function result value was too large
SELECT /*+ CURSOR_SHARING_EXACT */
*
FROM XMLTable(
'/HR/EMP'
passing xmltype( bfilename('DATA_PUMP_DIR','emp.xml'), nls_charset_id('CHAR_CS') )
columns
first_name varchar2(30) path 'FNAME',
last_name varchar2(30) path 'LNAME',
comments varchar2(4000) path 'COMMENT'
);
-------
I found another query where someone was doing a substring (I think to get only the first 4000 characters from the tag) here.
http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14638197 (See OP's post)
....
TERMINATION_DATE VARCHAR(32) path 'TerminateDate/substring(text(), 1, 32)',
....
So I updated my query to be
SELECT /*+ CURSOR_SHARING_EXACT */
*
FROM XMLTable(
'/HR/EMP'
passing xmltype( bfilename('DATA_PUMP_DIR','emp.xml'), nls_charset_id('CHAR_CS') )
columns
first_name varchar2(30) path 'FNAME',
last_name varchar2(30) path 'LNAME',
comments varchar2(4000) path 'COMMENT/substring(text(),1,4000)'
);
The query runs without an error when the <comment> tag has 4000 or less characters but still errors out with it is more than 4000.
I found an alternative method to do the SUBSTRING here in Herald ten Dam's reponse in
9701625
....
code varchar2(30) path 'substring(code,1,3)',
....
so I tried this:
SELECT /*+ CURSOR_SHARING_EXACT */
*
FROM XMLTable(
'/HR/EMP'
passing xmltype( bfilename('DATA_PUMP_DIR','emp.xml'), nls_charset_id('CHAR_CS') )
columns
first_name varchar2(30) path 'FNAME',
last_name varchar2(30) path 'LNAME',
comments varchar2(4000) path 'substring(COMMENT,1,4000)'
);
but that doesn't work either.
How can I extract the first 4000 characters of the <COMMENT> tag so that the query doesn't fail.
We are not using any other XMLDB features at this time. This is the first we've started looking into using Oracle built in XML features, so we might not have setup something that other's might know to specifically setup to start using the XML features in Oracle 11.1
Thanks in advance,
Wally