--------------------------------------------------------
1. create a Object directory xmldir
create or replace directory xmldir as ':E/file.xml';
2. create xmltype table
create table xmlfile_tbl of xmlTYPE;
3. Insert xmlfile to the table
insert into xmlfile_tblvalues(XMLType(bfilename('XMLDIR', 'CD1.XML'),nls_charset_id('AL16UTF8')));
Note :- Directory name Must be Block letter.
4. Then I try to Query it:
SQL> select object_value from xmlfile_tbl;
Return complete file.xml
5.example - 1
SELECT EXTRACTVALUE(VALUE(t), 'x/y') value_of_y, EXTRACTVALUE(VALUE(t), 'x/z') value_of_z FROM TABLE(XMLSEQUENCE(XMLTYPE.CreateXML('
6. example - 2
BEGIN FOR i IN ( SELECT EXTRACTVALUE(VALUE(t), '/B/ID') b_id, EXTRACTVALUE(VALUE(tc),'/D/ID') d_id FROM TABLE(XMLSEQUENCE(x.EXTRACT('A/B'))) t, TABLE(XMLSEQUENCE(EXTRACT(VALUE(t), 'B/C/D'))) tc ) LOOP dbms_output.put_line('B id : ' i.b_id ' : D id : ' i.d_id); END LOOP; END;
7. example - 3
DECLARE x XMLTYPE := XMLTYPE.CREATEXML('
-----------------------------------------------------------
sample XML file : BookStore.xml
-