Selecting (XML) data directly from disk
On the OTN XMLDB Forum, a question was asked if you could directly select from a XML file on disk, or to be more precise "
XQUERY / XMLTABLE Syntax to read and XML from a Windows local drive?". I had the idea that this could be easily done, nowadays via XMLDB functionality. So I tried it and came to the following conclusions. Although tested on Oracle 11.1.0.6.0 on Windows, this should also work on Oracle 10.2.x.

SQL> conn test/test<br />Connected.<br /> <br />SQL> -- The test user has the DBA role...<br /> <br />SQL> select * from v$version;<br /> <br />BANNER<br />-----------------------------------------------------------------------<br />Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production<br />PL/SQL Release 11.1.0.6.0 - Production<br />CORE 11.1.0.6.0 Production<br />TNS <font color="navy"><strong>for</strong></font> 32-bit Windows: Version 11.1.0.6.0 - Production<br />NLSRTL Version 11.1.0.6.0 - Production<br /> <br />5 rows selected.<br /> <br /><font color="darkgreen">/* The content of the data.xml file.<br /><br /><?xml version="1.0" encoding="UTF-8"?><br /><ROOT><br /> <ID>0</ID><br /> <INFO><br /> <INFO_ID>0</INFO_ID><br /> <INFO_CONTENT>Text</INFO_CONTENT><br /> </INFO><br /></ROOT><br /><br />*/</font><br /> <br />SQL> drop directory xmlstore;<br /> <br />Directory dropped.<br /> <br /> <br />SQL> -- the directory is on a Windows system...<br /> <br />SQL> create directory xmlstore as <font color="navy">'E:\temp'</font>;<br /> <br />Directory created.<br /> <br />SQL> create table test<br /> 2 (xmldata xmltype);<br /> <br />Table created.<br /> <br />SQL> INSERT into test<br /> 2 VALUES<br /> 3 (XMLTYPE(bfilename(<font color="navy">'XMLSTORE'</font>,<font color="navy">'data.xml'</font>),NLS_CHARSET_ID(<font color="navy">'AL32UTF8'</font>)));<br /> <br />1 row created.<br /> <br /> <br />SQL> set <font color="navy"><strong>long</strong></font> 100000000<br /> <br />SQL> select * from test;<br /> <br />XMLDATA<br />--------------------------------------------------------<br /><?xml version=<font color="red">"1.0"</font> encoding=<font color="red">"UTF-8"</font>?><br /><ROOT><br /> <ID>0</ID><br /> <INFO><br /> <INFO_ID>0</INFO_ID><br /> <INFO_CONTENT>Text</INFO_CONTENT><br /> </INFO><br /></ROOT><br /> <br /> <br />1 row selected.<br /> <br />SQL> select XMLTYPE(<font color="navy">'<ROOT><ID>0</ID><INFO><INFO_ID>0</INFO_ID><INFO_CONTENT>Text</INFO_CONTENT></INFO></ROOT>'</font>) as <font color="red">"XDATA"</font><br /> 2 from dual;<br /> <br />XDATA<br />------------------------------------------------------------------------------------------<br /><ROOT><ID>0</ID><INFO><INFO_ID>0</INFO_ID><INFO_CONTENT>Text</INFO_CONTENT></INFO></ROOT><br /> <br />1 row selected.<br /> <br /> <br />SQL> select XMLTYPE(bfilename(<font color="navy">'XMLSTORE'</font>,<font color="navy">'data.xml'</font>),NLS_CHARSET_ID(<font color="navy">'AL32UTF8'</font>)) as <font color="red">"XDATA"</font><br /> 2 from dual;<br />ERROR:<br />ORA-21500: internal error code, arguments: [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s]<br /> <br /> <br /> <br />no rows selected<br /> <br /> <br />SQL> select extract((XMLTYPE(bfilename(<font color="navy">'XMLSTORE'</font>,<font color="navy">'data.xml'</font>),NLS_CHARSET_ID(<font color="navy">'AL32UTF8'</font>))),<font color="navy">'*'</font>) as <font color="red">"XDATA"</font><br /> 2 from dual;<br /> <br />XDATA<br />------------------------------------------------------------------------------------------<br /><ROOT><ID>0</ID><INFO><INFO_ID>0</INFO_ID><INFO_CONTENT>Text</INFO_CONTENT></INFO></ROOT><br /> <br />1 row selected.<br /> <br />SQL> select xdata<br /> 2 from (XMLTABLE(<font color="navy">'*'</font><br /> 3 PASSING (XMLTYPE(bfilename(<font color="navy">'XMLSTORE'</font>,<font color="navy">'data.xml'</font>),NLS_CHARSET_ID(<font color="navy">'AL32UTF8'</font>)))<br /> 4 COLUMNS xdata xmltype PATH <font color="navy">'/*'</font><br /> 5 )<br /> 6 )<br /> 7 ;<br /> <br />XDATA<br />------------------------------------------------------------------------------------------<br /><ROOT><ID>0</ID><INFO><INFO_ID>0</INFO_ID><INFO_CONTENT>Text</INFO_CONTENT></INFO></ROOT><br />
Cheers
Marco
Hello Marco,
I have some questions about your article:
Can give any indication about the performance of this read action? Where is the greatest restriction in the performance?
Are there any restrictions on the file sizes other than the OS?
And in which circumstances would you preferably use this technique?
Cheers,
Karin