Load XML file and transform to table in database

Hi All,
If I have a xml file as sample xml data
<EMPLOYEES>
- <EMP>
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>17-DEC-80</HIREDATE>
<SAL>800</SAL>
</EMP>
</EMPLOYEES>
And I need to import to Emplyees table
Create table Employees
( EMPNO number,
ENAME varchar2(100),
JOB varchar2(100),
MGR number,
HIREDATE date,
SAL number
How to import the xml file to the table?
Regards,
Hiko

Well, if it's a complex XML you can use register a Schema and shred the XML to tables as described on the following thread:
Re: XML file processing into oracle
Or if it's fairly simple XML, you can just use XMLTABLE to flatten the data out...
SQL> ed
Wrote file afiedt.buf
  1  WITH xml_table AS
  2      (SELECT xmltype('
  3      <root>
  4        <child name="name1">
  5          <grandchild name="name11">
  6            <greatgrandchild name="name111"/>
  7            <greatgrandchild name="name112"/>
  8          </grandchild>
  9          <grandchild name="name12"/>
10       </child>
11       <child name="name2">
12         <grandchild name="name21"/>
13            <greatgrandchild name="name211"/>
14         <grandchild name="name22"/>
15       </child>
16     </root>') object_value FROM dual)
17     select po.child_name, gc.gchild_name, ggc.ggchild_name
18     from   xml_table p
19           ,xmltable('/root/child'
20                     passing p.object_value
21                     columns child_name  varchar2(100) path '@name'
22                           ,gchild      xmltype       path 'grandchild'
23                    ) po
24           ,xmltable('/grandchild'
25                     passing po.gchild
26                     columns gchild_name varchar2(100) path '@name'
27                            ,ggchild     xmltype       path 'greatgrandchild'
28                   ) (+) gc
29           ,xmltable('/greatgrandchild'
30                     passing gc.ggchild
31                     columns ggchild_name varchar2(100) path '@name'
32*                  ) (+) ggc
SQL> /
CHILD_NAME           GCHILD_NAME          GGCHILD_NAME
name1                name11               name111
name1                name11               name112
name1                name12
name2                name21
name2                name22and then insert the results into whatever table(s) you want.

Similar Messages

  • Loading XML files into an 8.0.6 database...

    Hi,
    I've got an Oracle 8.0.6 instance (Sun E250 Solaris 5.7) with multiple import data feeds. I am currently using SQL*Loader to load this data which are flat text delimited files. My data feeds will soon be supplying XML files instead of these flat files which is great, unfortunately, I will not be able to upgrade in 8.1.7 in time so that I can use the XML parser.
    Is there anyway I can use SQL*Loader or some other tool to load XML files into my 8.0.6 database? If there is a way, could someone please send the information I would need to help perform this task?
    Thanks for all your help...
    Gerry D'Costa
    Database Administrator
    [email protected]
    12Snap.com

    Check out the Oracle XDB Developer's Guide, Chapter 3. There is an example of using BFileName function to load the xml files from a directory object created using create or replace directory. It works really well.
    Ben

  • Reading from XML file and updating the table ????

    Hi
    I have package which reads the hier.XML file and does Update inserts into the 5 tables
    i have table called MAIN_tbl with the column cur_date.
    The package kicks if this cur_date is one day less than the hier.XML file DT.
    Currently i m manually checking this date's to make sure the Main_tbl cur_date is n sync with
    hier.XML file DT.
    for example :- hier.xml file DT is "20091020" then main_table cur_date should be 10/19/2009
    in order to kicks of the pakage.
    what i m looking to do ??
    compare the hier.xml DT with the main_table cur_date,
    if cur_date is -1(Preivous day) of hier.xml DT then run hier_pkg(Package)
    if not then update main_table cur_date to -1(previous day) of the hier.xml DATE
    Then later write the above logic to update the main_table in a procedure, and
    then call the package from the procedure.
    below are the top few lines of the hier.XML file which is relevant to the one which we are trying to do
    <?xml version = '1.0'?>
    <HIER_POSTING num ="111" HIER_TYP="CD" DT="20091020" Global="Y">
    FYI : The hier.XML file is located in UNIX space.
    How do i accomplish this. any idea ????
    Thank you so much in advance. For giving a thought on this problem!!!

    Any thought on this guys ???
    Thanks!!

  • Using sqlldr to load XML files and the file name ?  or access the file name

    I can use sqlldr to load the XML files when I declare the target table of XMLTYPE, but I need to load the filename and a sequence also with the XML in a table so we can mark wether the file passed validation or not.
    something like ....
    Create table test1
    lobfn varchar(200),
    load_number number,
    XML_COL XMLTYPE
    --------------- here is my sqlldr command
    sqlldr xml_user/xml_user load_test1.ctl
    LOAD DATA
    INFILE *
    INTO TABLE test1
    append
    xmltype(XML_COL)
    lobfn FILLER char TERMINATED by ',',
    XML_COL LOBFILE(lobfn) TERMINATED BY EOF
    BEGINDATA
    filename1.xml
    filename2.xml
    filename64.xml
    sqlldr comes back and says "commit point reached - logical record count 64
    but when I select count(*) from test1; it returns 0 rows.
    and when I
    SELECT X.* FROM tst1 P2,
    XMLTable ( '//XMLRoot//APPLICATION'
    PASSING P2.XML_COL
    COLUMNS
    "LASTNAME" CHAR(31) PATH 'LASTNAME',
    "FIRSTNAME" CHAR(31) PATH 'FIRSTNAME'
    ) AS X;
    It tells me invalid identifier ,
    Do I need to use a function to get the XML_COL as a object_value ???
    But when I create the table like
    create table test1 of XMLTYPE;
    and use sqlldr it works, but I dont have the file name, or dont know how to access it ??
    and I can use
    SELECT X.* FROM tst1 P2,
    XMLTable ( '//XMLRoot//APPLICATION'
    PASSING P2.object_value
    COLUMNS
    "LASTNAME" CHAR(31) PATH 'LASTNAME',
    "FIRSTNAME" CHAR(31) PATH 'FIRSTNAME'
    ) AS X;

    BTW
    Here's a trivial example of what you appear to be trying to do..
    C:\xdb\otn\sqlLoader>sqlplus scott/tiger @createTable
    SQL*Plus: Release 10.2.0.2.0 - Production on Wed Aug 2 22:08:10 2006
    Copyright (c) 1982, 2005, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> DROP TABLE TEST_TABLE
      2  /
    Table dropped.
    SQL> CREATE TABLE TEST_TABLE
      2  (
      3    filename    VARCHAR2(32),
      4    file_content xmltype
      5  )
      6  /
    Table created.
    SQL> quit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    C:\xdb\otn\sqlLoader>type sqlldr.ctl
    LOAD DATA
    INFILE 'filelist.txt'
       INTO TABLE TEST_TABLE
       FIELDS TERMINATED BY ','
        FILENAME       CHAR(32),
        FILE_CONTENT   LOBFILE(FILENAME) TERMINATED BY EOF
    C:\xdb\otn\sqlLoader>type filelist.txt
    testcase1.xml
    testcase2.xml
    C:\xdb\otn\sqlLoader>type testcase1.xml
    <foo/>
    C:\xdb\otn\sqlLoader>type testcase1.xml
    <foo/>
    C:\xdb\otn\sqlLoader>sqlldr userid=SCOTT/TIGER control=sqlldr.ctl log=sqlldr.log -direct
    SQL*Loader: Release 10.2.0.2.0 - Production on Wed Aug 2 22:08:11 2006
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Load completed - logical record count 2.
    C:\xdb\otn\sqlLoader>sqlplus scott/tiger
    SQL*Plus: Release 10.2.0.2.0 - Production on Wed Aug 2 22:08:18 2006
    Copyright (c) 1982, 2005, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> select * from TEST_TABLE
      2  /
    FILENAME
    FILE_CONTENT
    testcase1.xml
    <foo/>
    testcase2.xml
    <baa/>
    SQL>
    If you are interested in the 11g beta program please contact me directory at
    markDOTdrakeAToracleDOTcom

  • Loading xml file and parsing error in web start

    Hello,
    I load a xml file from jar file, but i have a error at parsing see :
    ClassLoader cl= this.getClass().getClassLoader();
    File file = new File(cl.getResource("paradise/test/maquette/parser/areas.xml").getFile());
    parseur.parse(new InputSource(new FileInputStream(file)), this);
    the file opening but at parseur.parse() i have a path error with :
    http:// . . . . \Paradise_client\paradise.jar!\paradise\test\maquette\parser\areas.xml , bad name of directories .....
    Can you help me ? please :-(

    I need to do a similar thing but in my case I don't know the structure of the xml file. I have 2 questions for this mapping. For an xml file like this:
    <?xml version="1.0"?>
    <catalog>
    <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <genre>Computer</genre>
    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <publisher>Dummy Publisher Co.</publisher>
    <publisher_address>
    <city>London</city>
    <street>Heart St.</street>
    <no>23/5</no>
    </publisher_address>
    <description>An in-depth look at creating applications
    with XML.
    </description>
    </book>
    </catalog>
    If I'm right, I need to create a database named catalog and a table named book. But the problem comes out here: How can i store publisher_address? In a table or what? Other problem is, is there a difference between storing id attribute of the book and genre element of the book? I think they are just columns of the book table. But if I'm wrong what is the correct solution?

  • Read data from xml files and  populate internal table

    Hi.
    How to read data from xml files into internal tables?
    Can u tell me the classes and methods to read xml data..
    Can u  explain it with a sample program...

    <pre>DATA itab_accontextdir TYPE TABLE OF ACCONTEXTDIR.
    DATA struct_accontextdir LIKE LINE OF itab_accontextdir.
    DATA l_o_error TYPE REF TO cx_root.
    DATA: filename type string ,
                 xmldata type xstring .
    DATA: mr      TYPE REF TO if_mr_api.
    mr = cl_mime_repository_api=>get_api( ).
    mr->get( EXPORTING  i_url     = 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'
                  IMPORTING  e_content = xmldata ).
    WRITE xmldata.
    TRY.
    CALL TRANSFORMATION id
          SOURCE XML xmldata
          RESULT shiva = itab_accontextdir.
      CATCH cx_root INTO l_o_error.
    ENDTRY.
    LOOP AT itab_accontextdir INTO struct_accontextdir.
        WRITE: / struct_accontextdir-context_id,
               struct_accontextdir-context_name,
               struct_accontextdir-context_type.
        NEW-LINE.
        ENDLOOP.</pre>
    <br/>
    Description:   
    In the above code snippet I am storing the data in an xml file(you know xml is used to store and transport data ) called 'xml_accontextdir.xml' that is uploaded into the MIME repository at path 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'.
    The below API is used to read a file in MIME repo and convert it into a string that is stored in ' xmldata'. (This is just a raw data that is got by appending the each line of  xml file).
    mr = cl_mime_repository_api=>get_api( ).
    mr->get( EXPORTING  i_url     = 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'
                  IMPORTING  e_content = xmldata ).
        Once the 'xmldata' string is available we use the tranformation to parse the xml string that we have got from the above API and convert it into the internal table.
    <pre>TRY.
    CALL TRANSFORMATION id
          SOURCE XML xmldata
          RESULT shiva = itab_accontextdir.
      CATCH cx_root INTO l_o_error.
    ENDTRY.</pre>
    Here the trasnsformation 'id ' is used to conververt the source xml 'xmldata' to resulting internal table itab_accontextdir, that have same structure as our xml file 'xml_accontextdir.xml'.  In the RESULT root of the xml file has to be specified. (In my the root is 'shiva'). 
    Things to be taken care:
    One of the major problem that occurs when reading the xml file is 'format not compatible with the internal table' that you are reading into internal table.  Iin order to get rid of this issue use one more tranformation to convert the data from the internal table into the xml file.    
    <pre>TRY.
          CALL TRANSFORMATION id
            SOURCE shiv = t_internal_tab
            RESULT XML xml.
        CATCH cx_root INTO l_o_error.
      ENDTRY.
      WRITE xml.
      NEW-LINE.</pre>
    <br/>
    This is the same transformation that we used above but the differnce is that the SOURCE and RESULT parameters are changed the source is now the internal table and result is *xml *string. Use xml browser that is available with the ABAP workbench to read the xml string displayed with proper indentation. In this way we get the format of xml file to be used that is compatable with the given internal table. 
    Thank you, Hope this will help you!!!
    Edited by: Shiva Prasad L on Jun 15, 2009 7:30 AM
    Edited by: Shiva Prasad L on Jun 15, 2009 11:56 AM
    Edited by: Shiva Prasad L on Jun 15, 2009 12:06 PM

  • Getting data from an XML file and pushing it to a database

    I need to create a coldfusion page that grabs an incoming xml file, extract the data and then push it into a database. I have never done anything like this, and have been reading as much as I can find. Can anyone recomend a good resource or give me a hand on how I go about doing this?
    The xml file is coming from another page. Basically the source page is a simple text box that an xml file is pasted into and submited. The action page must grab the xml file, pull out the data and funnel it into a table. Then it must query the table and based on the results of the query, push a new xml file back to the user.
    <my brain is already hurting>

    I'd start by looking at the CF documentation related to XML and Ben Forta's books.
    "About XML and ColdFusion" from CF docs:
    http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec133ba -8000.html
    Ben Forta's books
    http://www.forta.com/books/0321679199/
    It would be good to know:
    1. What the workflow is for your task. Can you describe your task in detail and provide samples of the XML and database?
    2. The database you are using and the structure of your tables.
    3. The version of CF you are using.

  • Error while loading xml files using JDBC

    Hi,
    I am trying to load xml files into an xmltype table using JDBC calls and am getting this error for some files
    LPX-00200: could not convert from encoding UTF-8 to UCS2
    The xml files and our database are both UTF-8 encoded. The version of oracle that we have here is 9.2.0.6
    Any suggestions in this matter will be greatly appreciated.
    Thanks,
    Uma

    I also experienced this problem and unfortunately this solution didn't work for me given that the tag you suggested was already on the XML file.

  • ORA-22288:file or LOB operation FILEOPEN failed while loading XML file.

    Hello all,
    I am getting the following error messages while loading XML file to Oracle 9i table.
    declare
    ERROR at line 1:
    ORA-22288: file or LOB operation FILEOPEN failed
    No such file or directory
    ORA-06512: at "SYS.DBMS_LOB", line 504
    ORA-06512: at line 10
    The script I am using is all follows:-
    1. Created a file ldxmldata.sh on unix server directory
    dd conv=ucase if=$1|sed 's/<?XML/<?xml/'|sed 's/VERSION/version/'|sed 's
    /RECORD/ROW/'|sed 's/DATE/TRANSDATE/'|sed 's/&/-/'|sed 's/\/DATE>// TRANSDATE>/'>$1.UCASE
    sqlplus sales/sales@rac @upld.sql $1.UCASE
    2. Created SQL file upld.sql on unix server
    set serveroutput on
    exec DBMS_JAVA.SET_OUTPUT(1000000);
    @ldxml.sql bsl.xml.UCASE
    commit;
    exit
    3. Created sql file ldxml.sql on unix server
    declare
    insCtx DBMS_XMLSave.ctxType;
    rows number;
    file bfile := bfilename('XML_DIR','&1');
    charContent CLOB := ' ';
    targetFile bfile;
    warning number;
    begin
    targetFile := file;
    DBMS_LOB.fileopen(targetFile, DBMS_LOB.file_readonly);
    DBMS_LOB.loadfromFile(charContent,targetFile,DBMS_LOB.getLength(tar
    getFile),1,1);
    insCtx := DBMS_XMLSave.newContext('sales.s_price');
    rows := DBMS_XMLSave.insertXML(insCtx,charContent);
    DBMS_XMLSave.closeContext(insCtx);
    DBMS_LOB.fileclose(targetFile);
    end;
    4. As Sys,
    Created a directory XML_DIR and assigned it the path of Unix server directory
    where the script files reside.
    Granted read priviledge on XML_DIR to user sales.
    I am getting the above error messages. Kindly help with some possible solution.
    Arun Patodia
    Bokaro Steel City

    Hi guys,
    Sybrand, aplogoies, the second line of the error stack was on one line in the first post, full error stack below:
    ORA-22288: file or LOB operation FILEOPEN failed
    The program issued a command but the command length is incorrect.
    ORA-06512: at "SYS.DBMS_LOB", line 716
    ORA-06512: at "JLMS.LOAD_DATA_UTIL", line 417
    ORA-06512: at line 2I have looked at that error code as you mentioned, but the second line here doesn't really help much.
    Hoek, i took your advice and tried to replace FILEOPEN with OPEn but got the same error.
    Just to clarify as well, I am not using UNC or relative file paths as I know that these can cause problems.
    Rgds
    Dan

  • Loading XML File to Physical table in BW

    Hi,
    I have a requirement to load XML file BW physical table.
    The XML file that I am getting looks pretty complex compared to the XML file I have seen online.
    I need help in transforming the file and Abap code to load the file to physical table
    I have already created the table in SE11.
    XML file
    <?xml version="1.0"?>
    <?mso-application progid="Excel.Sheet"?>
    <Row ss:AutoFitHeight="0" ss:Height="36">
        <Cell ss:StyleID="s62"><Data ss:Type="String">First Name</Data></Cell>
        <Cell ss:StyleID="s62"><Data ss:Type="String">Bank Name -
    add. info</Data></Cell>
       </Row>
       <Row ss:AutoFitHeight="0" ss:Height="22.5" ss:StyleID="s67">
        <Cell><Data ss:Type="String">John Mayor</Data></Cell>
        <Cell><Data ss:Type="String">New: Local bank</Data></Cell
       </Row>
    my requirement is to get this values into physical table i.e
    First name                 bank name
    John Mayor               new: local bank
    thanks
    Edited by: Bhat Vaidya on Apr 14, 2010 11:59 AM
    Edited by: Bhat Vaidya on Apr 14, 2010 12:00 PM
    Edited by: Bhat Vaidya on Apr 14, 2010 12:01 PM
    Edited by: Bhat Vaidya on Apr 14, 2010 12:01 PM

    No longer working on the issue.

  • OWB11gR2 - simple and easy way to load XML formatted data into db tables?

    Hi,
    we're currently trying to load table data stored in XML files into our datawarehouse using OWB 11gR2.
    However, we're finding this is not quite as trivial as loading flat files...
    Most postings on this forum points to the blog-entry title "Leveraging XDB" found here (http://blogs.oracle.com/warehousebuilder/2007/09/leveraging_xdb.html).
    This blog also references the zip-file owb_xml_etl_utils.zip, which seems to have disappeared from it's original location and can now be found on sourceforge.
    Anyway, the solution described is for OWB 10g, and when trying to import experts from the zip-file etc. we end up not being able to run the "Create ETL from XSD" expert, as the 11gR2 client is different from the 10g and does not have the Experts menu et.al.
    Also, this solution was published over 3 years ago, and it seems rather strange that importing XML-formatted data should still be so cumbersome in the newer warehouse builder releases.
    The OWB 11gR2 documentation is very sparse (or rather - quite empty) on how to load XML data, all it has is a few lines on "XML Transformations", giving no clue as to how one goes about loading data.
    Is this really the state of things? Or are we missing some vital information here?
    We'd have thought that with 11g-releases, loading XML-data would be rather simple, quick and painless?
    Is there somewhere besides the blog mentioned above where we can find simple and to the point guidelines for OWB 11gR2 on how to load XML-formatted data into Oracle tables?
    Regards,
    -Haakon-

    Yes it is possible to use SQL*Loader to parse and load XML, but that is not what it was designed for and so is not recommended. You also don't need to register a schema, just to load/store/parse XML in the DB either.
    So where does that leave you?
    Some options
    {thread:id=410714} (see page 2)
    {thread:id=1090681}
    {thread:id=1070213}
    Those talk some about storage options and reading in XML from disk and parsing XML. They should also give you options to consider. Without knowing more about your requirements for the effort, it is difficult to give specific advice. Maybe your 7-8 tables don't exist and so using Object Relational Storage for the XML would be the best solution as you can query/update tables that Oracle creates based off the schema associated to the XML. Maybe an External Table definition works better for reading the XML into the system because this process will happen just once. Maybe using WebDAV makes more sense for loading XML to be parsed (I don't have much experience with this, just know it is possible from what I've read on the forums). Also, your version makes a difference as you have different options available depending upon the version of Oracle.
    Hope all that helps as a starter.
    Edited by: A_Non on Jul 8, 2010 4:31 PM
    A great example, see the answers by mdrake in {thread:id=1096784}

  • Loading XML File in Oracle Tables through Concurrent Request

    I am posting a working program which reads an XML File and loads in Oracle database table through Concurrent Request. Input parameter for this program is file name. I have added directory name ASPEN_DIR as /interface/inbound in ALL_DIRECTORIES table.
    /* This is a sample program reading an input xml file and loads data in Oracle Database table
    This program is executed through concurrent request and it has an input file name
    it also creates a log for reading and inserting records from file and into a table
    CREATE OR REPLACE PACKAGE BODY CBAP_ACCRUENT_XML_PKG AS
    PROCEDURE read_emp_xml_file (errbuf out varchar2,
    retcode out number,
    in_filename in varchar2)
    is
    my_dir varchar2(10) := 'ASPEN_DIR';
    l_bfile BFILE;
    l_clob CLOB;
    l_parser dbms_xmlparser.Parser;
    l_doc dbms_xmldom.DOMDocument;
    l_nl dbms_xmldom.DOMNodeList;
    l_n dbms_xmldom.DOMNode;
    l_temp VARCHAR2(1000);
    v_empno number(10);
    v_ename varchar2(50);
    v_job varchar2(30);
    v_mgr number(10);
    v_hiredate date;
    v_sal number(10);
    v_comm number(10);
    src_csid NUMBER := NLS_CHARSET_ID('UTF8');
    v_read NUMBER(5);
    v_insert NUMBER(5);
    dest_offset INTEGER := 1;
    src_offset INTEGER := 1;
    lang_context INTEGER := dbms_lob.default_lang_ctx;
    warning INTEGER;
    BEGIN
    v_read := 0;
    v_insert := 0;
    l_bfile := BFileName(my_dir, in_filename);
    dbms_lob.createtemporary(l_clob, cache=>FALSE);
    dbms_lob.open(l_bfile, dbms_lob.lob_readonly);
    dbms_lob.loadclobfromfile(l_clob, l_bfile, dbms_lob.getlength(l_bfile), dest_offset,src_offset, src_csid, lang_context, warning);
    dbms_lob.close(l_bfile);
    -- make sure implicit date conversions are performed correctly
    dbms_session.set_nls('NLS_DATE_FORMAT','''DD/MM/RR HH24:MI:SS''');
    -- Create a parser.
    l_parser := dbms_xmlparser.newParser;
    -- Parse the document and create a new DOM document.
    dbms_xmlparser.parseClob(l_parser, l_clob);
    l_doc := dbms_xmlparser.getDocument(l_parser);
    -- Free resources associated with the CLOB and Parser now they are no longer needed.
    dbms_lob.freetemporary(l_clob);
    dbms_xmlparser.freeParser(l_parser);
    -- Get a list of all the nodes in the document using the XPATH syntax.
    l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),'/EMPLOYEES/EMP');
    -- Loop through the list and create a new record in a tble collection
    -- for each record.
    FOR cur_emp IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
    l_n := dbms_xmldom.item(l_nl, cur_emp);
    v_read := v_read + 1;
    -- Use XPATH syntax to assign values to he elements of the collection.
    dbms_xslprocessor.valueOf(l_n,'EMPNO/text()',v_empno);
    dbms_xslprocessor.valueOf(l_n,'ENAME/text()',v_ename);
    dbms_xslprocessor.valueOf(l_n,'JOB/text()',v_job);
    dbms_xslprocessor.valueOf(l_n,'MGR/text()',v_mgr);
    dbms_xslprocessor.valueOf(l_n,'HIREDATE/text()',v_hiredate);
    dbms_xslprocessor.valueOf(l_n,'SAL/text()',v_sal);
    dbms_xslprocessor.valueOf(l_n,'COMM/text()',v_comm);
    insert into emp(empno,ename,job,mgr,hiredate,sal,comm)
    values(v_empno,v_ename,v_job,v_mgr,v_hiredate,v_sal,v_comm);
    v_insert := v_insert + 1;
    END LOOP;
    -- Free any resources associated with the document now it
    -- is no longer needed.
    dbms_xmldom.freeDocument(l_doc);
    --remove file to another directory
    commit;
    fnd_file.put_line(fnd_file.LOG,'Number of Records Read : '||v_read);
    fnd_file.put_line(fnd_file.LOG,'Number of Records Insert : '||v_insert);
    EXCEPTION
    WHEN OTHERS THEN
    dbms_lob.freetemporary(l_clob);
    dbms_xmlparser.freeParser(l_parser);
    dbms_xmldom.freeDocument(l_doc);
    retcode := sqlcode;
    ERRBUF := sqlerrm;
    ROLLBACK;
    END read_emp_xml_file;
    END;
    <?xml version="1.0" ?>
    - <EMPLOYEES>
    - <EMP>
    <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7902</MGR>
    <HIREDATE>17-DEC-80</HIREDATE>
    <SAL>800</SAL>
    </EMP>
    - <EMP>
    <EMPNO>7499</EMPNO>
    <ENAME>ALLEN</ENAME>
    <JOB>SALESMAN</JOB>
    <MGR>7698</MGR>
    <HIREDATE>20-FEB-81</HIREDATE>
    <SAL>1600</SAL>
    <COMM>300</COMM>
    </EMP>
    - <EMP>
    <EMPNO>7521</EMPNO>
    <ENAME>WARD</ENAME>
    <JOB>SALESMAN</JOB>
    <MGR>7698</MGR>
    <HIREDATE>22-FEB-81</HIREDATE>
    <SAL>1250</SAL>
    <COMM>500</COMM>
    </EMP>
    - <EMP>
    <EMPNO>7566</EMPNO>
    <ENAME>JONES</ENAME>
    <JOB>MANAGER</JOB>
    <MGR>7839</MGR>
    <HIREDATE>02-APR-81</HIREDATE>
    <SAL>2975</SAL>
    </EMP>
    - <EMP>
    <EMPNO>7654</EMPNO>
    <ENAME>MARTIN</ENAME>
    <JOB>SALESMAN</JOB>
    <MGR>7698</MGR>
    <HIREDATE>28-SEP-81</HIREDATE>
    <SAL>1250</SAL>
    <COMM>1400</COMM>
    </EMP>
    - <EMP>
    <EMPNO>7698</EMPNO>
    <ENAME>BLAKE</ENAME>
    <JOB>MANAGER</JOB>
    <MGR>7839</MGR>
    <HIREDATE>01-MAY-81</HIREDATE>
    <SAL>2850</SAL>
    </EMP>
    - <EMP>
    <EMPNO>7782</EMPNO>
    <ENAME>CLARK</ENAME>
    <JOB>MANAGER</JOB>
    <MGR>7839</MGR>
    <HIREDATE>09-JUN-81</HIREDATE>
    <SAL>2450</SAL>
    </EMP>
    - <EMP>
    <EMPNO>7788</EMPNO>
    <ENAME>SCOTT</ENAME>
    <JOB>ANALYST</JOB>
    <MGR>7566</MGR>
    <HIREDATE>19-APR-87</HIREDATE>
    <SAL>3000</SAL>
    </EMP>
    - <EMP>
    <EMPNO>7839</EMPNO>
    <ENAME>KING</ENAME>
    <JOB>PRESIDENT</JOB>
    <HIREDATE>17-NOV-81</HIREDATE>
    <SAL>5000</SAL>
    </EMP>
    - <EMP>
    <EMPNO>7844</EMPNO>
    <ENAME>TURNER</ENAME>
    <JOB>SALESMAN</JOB>
    <MGR>7698</MGR>
    <HIREDATE>08-SEP-81</HIREDATE>
    <SAL>1500</SAL>
    <COMM>0</COMM>
    </EMP>
    - <EMP>
    <EMPNO>7876</EMPNO>
    <ENAME>ADAMS</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7788</MGR>
    <HIREDATE>23-MAY-87</HIREDATE>
    <SAL>1100</SAL>
    </EMP>
    - <EMP>
    <EMPNO>7900</EMPNO>
    <ENAME>JAMES</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7698</MGR>
    <HIREDATE>03-DEC-81</HIREDATE>
    <SAL>950</SAL>
    </EMP>
    - <EMP>
    <EMPNO>7902</EMPNO>
    <ENAME>FORD</ENAME>
    <JOB>ANALYST</JOB>
    <MGR>7566</MGR>
    <HIREDATE>03-DEC-81</HIREDATE>
    <SAL>3000</SAL>
    </EMP>
    - <EMP>
    <EMPNO>7934</EMPNO>
    <ENAME>MILLER</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7782</MGR>
    <HIREDATE>23-JAN-82</HIREDATE>
    <SAL>1300</SAL>
    </EMP>
    </EMPLOYEES>

    http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10790/toc.htm
    Take a look at Examples 4-8 and 4-9. Even thought this is 10g doc code should work on 9.2.4 or later

  • Loading XML file into DB Table

    Hi
    I m quite new to the loading XML file into database table.
    It will be great if anyone could guide me to through.
    Now,
    i have an XML file which has to be loaded into the DB table.
    what are the steps involved in doing this. How do i go from here ??
    your help is greatly appriciated ???
    Thank you so much!!
    -Shashi

    OK - Although you really should read the XMLDB FAQ on this forum, here is some sample code of ONE of the ways of doing it
    (there are multiple ways - and this is not the most simple one)
    Based on Oracle 11gR1
    -- sqlplus /nolog
    clear screen
    set termout on
    set feed on
    set lines 40
    set long 10000000
    set serveroutput on
    set lines 100
    set echo on
    connect / as sysdba
    col filename for a80
    col xml      for a80
    -- Create schema “OTN”
    drop user OTN cascade;
    purge dba_recyclebin;
    create user OTN identified by OTN;
    grant dba, xdbadmin to OTN;
    EXECUTE dbms_java.grant_permission( 'OTN', 'java.io.FilePermission','G:\OTN\xmlstore','read' );
    prompt pause
    pause
    clear screen
    -- Create directory
    connect OTN/OTN;
    show user
    drop directory OTN_USE_CASE;
    CREATE directory OTN_USE_CASE AS 'G:\OTN\xmlstore';
    SELECT extract((XMLTYPE(bfilename('OTN_USE_CASE','ABANDA-20030407215829881GMT.xml'),NLS_CHARSET_ID('AL32UTF8'))),'*') AS "XML"
    from   dual;
    prompt pause
    pause
    clear screen
    -- Directory Listing - Tom Kyte
    create global temporary table DIR_LIST
    ( filename varchar2(255) )
    on commit delete rows
    create or replace
      and compile java source named "DirList"
    as
    import java.io.*;
    import java.sql.*;
    public class DirList
    {public static void getList(String directory)
                       throws SQLException
    {   File path = new File( directory );
        String[] list = path.list();
        String element;
        for(int i = 0; i < list.length; i++)
        {   element = list;
    #sql { INSERT INTO DIR_LIST (FILENAME)
    VALUES (:element) };
    create or replace procedure get_dir_list( p_directory in varchar2 )
    as language java
    name 'DirList.getList( java.lang.String )';
    prompt pause
    pause
    clear screen
    -- The content of the global temporary table
    exec get_dir_list( 'G:\OTN\xmlstore' );
    select * from dir_list;
    -- "COMMIT" will clear / truncate the global temporary table...
    prompt pause
    pause
    clear screen
    -- Combined: Reading XML content from multiple XML files
    commit;
    exec get_dir_list( 'G:\OTN\xmlstore' );
    select * from dir_list where filename like '%.xml'
    and rownum <= 10;
    prompt pause
    pause
    clear screen
    select extract((XMLTYPE(bfilename('OTN_USE_CASE',dl.filename),NLS_CHARSET_ID('AL32UTF8'))),'*') AS "XML"
    from dir_list dl
    where dl.filename like '%.xml' and rownum <= 2;
    prompt pause
    pause
    clear screen
    -- If you can select it you can insert it...
    -- drop table OTN_xml_store purge;
    create table OTN_xml_store of xmltype
    xmltype store as binary xml
    commit;
    exec get_dir_list( 'G:\OTN\xmlstore' );
    set time on timing on
    insert into OTN_xml_store
    select XMLTYPE(bfilename('OTN_USE_CASE',dl.filename),NLS_CHARSET_ID('AL32UTF8')) AS "XML"
    from dir_list dl
    where dl.filename like '%.xml';
    set time off timing off
    commit;
    select count(*) from OTN_xml_store;
    prompt pause
    pause
    clear screen
    -- If you can select it you can create resources and files
    set time on timing on
    commit;
    exec get_dir_list( 'G:\OTN\xmlstore' );
    select count(*) from dir_list where filename like '%.xml';
    set serveroutput on size 10000
    DECLARE
    XMLdoc XMLType;
    res BOOLEAN;
    v_foldername varchar2(4000) := '/public/OTN/';
    cursor c1
    is
    select dl.filename FNAME
    , XMLTYPE(bfilename('OTN_USE_CASE',dl.filename),NLS_CHARSET_ID('AL32UTF8')) XMLCONTENT
    from dir_list dl
    where dl.filename like '%.xml'
    and rownum <= 100;
    BEGIN
    -- Create XDB repository Folder
    if (dbms_xdb.existsResource(v_foldername))
    then
    dbms_xdb.deleteResource(v_foldername,dbms_xdb.DELETE_RECURSIVE_FORCE);
    end if;
    res:=DBMS_XDB.createFolder(v_foldername);
    -- Create XML files in the XDB Repository
    for r1 in c1
    loop
    if (DBMS_XDB.CREATERESOURCE(v_foldername||r1.fname, r1.xmlcontent))
    then
    dbms_output.put_line(v_foldername||r1.fname);
    null;
    else
    dbms_output.put_line('Loop Exception :'||sqlerrm);
    end if;
    end loop;
    EXCEPTION WHEN OTHERS THEN
    dbms_output.put_line('Others Exception: '||sqlerrm);
    END;
    set time off timing off
    commit;
    prompt pause
    pause
    clear screen
    -- FTP and HTTP
    clear screen
    prompt
    prompt *** FTP - Demo ***
    prompt
    prompt pause
    pause
    host ftp
    -- open localhost 2100
    -- user OTN OTN
    -- cd public
    -- cd OTN
    -- ls
    -- bye
    clear screen
    prompt
    prompt *** Microsoft Internet Explorer - Demo ***
    prompt
    prompt pause
    pause
    host "C:\Program Files\Internet Explorer\IEXPLORE.EXE" http://OTN:OTN@localhost:8080/public/OTN/
    prompt pause
    pause
    -- Accessing the XDB Repository content via Resource View
    -- Selecting content from a resource via XBDUriType
    clear screen
    prompt set long 300
    set long 300
    prompt Relative Path - (path)
    SELECT path(1) as filename
    FROM RESOURCE_VIEW
    WHERE under_path(RES, '/public/OTN', 1) = 1
    and rownum <= 10
    prompt pause
    pause
    clear screen
    prompt Absolute Path - (any_path)
    select xdburitype(any_path).getClob() as xml
    FROM RESOURCE_VIEW
    WHERE under_path(RES, '/public/OTN', 1) = 1
    and rownum <= 1;
    prompt pause
    pause
    -- CLEANUP ENVIRONMENT
    clear screen
    prompt
    prompt >>>>> Clean UP !!! <<<<<<
    prompt
    prompt Cleanup environment and drop user...!!!
    prompt
    pause
    clear screen
    conn / as sysdba
    alter session set current_schema=OTN;
    begin
    dbms_xdb.deleteResource('/public/OTN',dbms_xdb.DELETE_RECURSIVE_FORCE);
    commit;
    end;
    alter session set current_schema=sys;
    drop user OTN cascade;
    Based on http://www.liberidu.com/blog/?p=1053

  • Need to Load data in XML file into multiple Oracle tables

    Experts
    I want to load data that is stored at XML file into multiple Oracle table using plsql.
    I am novice in this area.Kindly explain in depth or step by step so that i can achive this.
    Thanks in advnace.

    Hi,
    extract your xml and then you can use insert all clause.
    here's very small example on 10.2.0.1.0
    SQL> create table table1(id number,val varchar2(10));
    Table created.
    SQL> create table table2(id number,val varchar2(10));
    Table created.
    SQL> insert all
      2  into table1 values(id,val)
      3  into table2 values(id2,val2)
      4  select extractValue(x.col,'/a/id1') id
      5        ,extractValue(x.col,'/a/value') val
      6        ,extractValue(x.col,'/a/value2') val2
      7        ,extractValue(x.col,'/a/id2') id2
      8  from (select xmltype('<a><id1>1</id1><value>a</value><id2>2</id2><value2>b</value2></a>') col from dual) x;
    2 rows created.
    SQL> select * from table1;
            ID VAL                                                                 
             1 a                                                                   
    SQL> select * from table2;
            ID VAL                                                                 
             2 b                                                                    Ants

  • Loading XML files into Database table

    Loading XML files into Database table
    Hi I have some XML files say 100 files in a virtual directory created using &quot;Create or replace directory command&quot; and those files need to be loaded into a table having a column of XMLTYPE. 1)How to load that using Oracle provided procedures/packages

    Check out the Oracle XDB Developer's Guide, Chapter 3. There is an example of using BFileName function to load the xml files from a directory object created using create or replace directory. It works really well.
    Ben

Maybe you are looking for

  • OLE_FLUSH_CALL invalid param verb: textstream

    I'm developing a program that uses a whole load of alv grids on different tabs.  When I process one particularl okcode, I get a dump: <b>Exception condition "INVALID PARAM VERB: TEXTSTREAM" raised.</b><br> <br> <PRE>Trigger Location of Runtime Error

  • How do I create a toggle (hide/show) button in Captivate 5?

    What is the best method to create a button that will hide / show a particular caption? I looked into using an advanced action, but have not been successful in indicating the correct variable / control statement to make it work. Anyone have a button w

  • 3G Camera App has disappeared!

    I discovered the other day as I went to take a photo that the app for the camera has vanished! We had been away for a week and I had not 'sync'd the phone in that time. I have only just got home and as yet not sure if I should sync the phone to see i

  • Is there a default ContextMenu?

    I notice that when I right click on a textarea, I get a menu of standard items. Is this a contextmenu? can I add to this using getContextmenu? I ask because I assumed the answer to be yes but get a null ptr exception when I try to add a menu item. I

  • JFileChooser or FileDialog.... so many questions

    hi all, i have searched the forum to no avail so i need your help. i am wanting to use jfilechooser to get the directory listing and files over a tcp/ip connection. i send the getdirectory message to the server and it returns the directory. next, i s