Issues du read XML into Oracle

Hello all,
I try to insret XML data into Oracle, and I looked on forum for tips. I found (I think) the way to do it, but I have an error :
Here is what I did : I created a table of XMLType (OK) :
CREATE TABLE XML_TAB ( xmlval XMLType);
Then I insert data directly (OK):
INSERT INTO XML_TAB VALUES (
xmltype('<?xml version="1.0"?>
<EMP>
<EMPNO>221</EMPNO>
<ENAME>John</ENAME>
</EMP>'));
Now, I want to import directly from a XML file. I try this :
INSERT INTO Xml_tab
VALUES
xmltype(bfilename('xml_dir','essai2.xml'),nls_charset_id('AL32UTF8'))
it fails with ORA-06553: PLS-306: numéro ou types d'arguments erronés dans appel à 'XMLTYPE' (xml_dir is setup)
or this :
INSERT INTO Xml_tab
VALUES
xmltype('D:/TMP/XML/essai2.xml',nls_charset_id('AL32UTF8'))
it fails with ORA-06553: PLS-307: trop de déclarations de 'XMLTYPE' correspondent à cet appel
I try with Oracle 9i.
Did I miss something ?
I'm not far to succeed what I want to do. Thank's a lot for your help.
Antoine

Hello,
Thanks for you answer. Oracle version is 9.2.0.4.0.
Thanks also for the BFILENAME information. My problem remains that if I try to read by entering directly the filename, I have the PLS307 error.
I will check the XMLDB FAQ, but I have seen several documentation, and process is always the same, as I do...except for the error.
I will also try in 10g, to see if it works better.
Antoine

Similar Messages

  • Read xml into oracle table

    Hi,
    How can I read an xml.file read in an oracle table (invoice varchar2(20), invoice_line number, ship_date date, country varchar2(100))?
    The xml looks like this:
    <?xml version="1.0" encoding="utf-8" ?>
    - <dataset xmlns="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
    - <!--
    <dataset
    xmlns="http://developer.cognos.com/schemas/xmldata/1/"
    xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
    xs:schemaLocation="http://developer.cognos.com/schemas/xmldata/1/ xmldata.xsd"
    >
    -->
    - <metadata>
    <item name="Invoice #" type="xs:string" length="42" />
    <item name="Invoice Line" type="xs:string" length="10" />
    <item name="Ship Date" type="xs:date" />
    <item name="COUNTRY" type="xs:string" length="8" />
    </metadata>
    - <data>
    - <row>
    <value>26623</value>
    <value>0001</value>
    <value>2010-05-03</value>
    <value>USA</value>
    </row>
    - <row>
    <value>26624</value>
    <value>0001</value>
    <value>2010-05-03</value>
    <value>USA</value>
    </row>
    - <row>
    <value>26624</value>
    <value>0003</value>
    <value>2010-05-03</value>
    <value>USA</value>
    </row>
    - <row>
    <value>26625</value>
    <value>0001</value>
    <value>2010-05-03</value>
    <value>USA</value>
    </row>
    </data>
    </dataset>
    Thnx, Robbert

    Hi,
    Possible solutions will depend on your db version, which you didn't give.
    The following example assumes you're using 10gR2 :
    CREATE TABLE invoices (
    invoice varchar2(20),
    invoice_line number,
    ship_date date,
    country varchar2(100)
    DECLARE
    xmldoc xmltype := xmltype(
    '<?xml version="1.0" encoding="utf-8" ?>
    <dataset xmlns="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
    <metadata>
    <item name="Invoice #" type="xs:string" length="42" />
    <item name="Invoice Line" type="xs:string" length="10" />
    <item name="Ship Date" type="xs:date" />
    <item name="COUNTRY" type="xs:string" length="8" />
    </metadata>
    <data>
    <row>
    <value>26623</value>
    <value>0001</value>
    <value>2010-05-03</value>
    <value>USA</value>
    </row>
    <row>
    <value>26624</value>
    <value>0001</value>
    <value>2010-05-03</value>
    <value>USA</value>
    </row>
    <row>
    <value>26624</value>
    <value>0003</value>
    <value>2010-05-03</value>
    <value>USA</value>
    </row>
    <row>
    <value>26625</value>
    <value>0001</value>
    <value>2010-05-03</value>
    <value>USA</value>
    </row>
    </data>
    </dataset>'
    BEGIN
      INSERT INTO invoices (invoice, invoice_line, ship_date, country)
      SELECT invoice, invoice_line, to_date(ship_date, 'YYYY-MM-DD'), country
      FROM XMLTable(
       XMLNamespaces(default 'http://developer.cognos.com/schemas/xmldata/1/'),
       '/dataset/data/row'
       passing xmldoc
       columns
         invoice      varchar2(20)  path 'value[1]',
         invoice_line number        path 'value[2]',
         ship_date    varchar2(10)  path 'value[3]',
         country      varchar2(100) path 'value[4]'
    END;
    /If your XML document resides outside the database, you may also access it directly through a DIRECTORY object :
    CREATE OR REPLACE DIRECTORY xmldir AS 'C:\oracle\invoices\xml';
    INSERT INTO invoices (invoice, invoice_line, ship_date, country)
    SELECT invoice, invoice_line, to_date(ship_date, 'YYYY-MM-DD'), country
    FROM XMLTable(
    XMLNamespaces(default 'http://developer.cognos.com/schemas/xmldata/1/'),
    '/dataset/data/row'
    passing xmltype( bfilename('XMLDIR', 'invoices.xml'), nls_charset_id('AL32UTF8') )
    columns
       invoice      varchar2(20)  path 'value[1]',
       invoice_line number        path 'value[2]',
       ship_date    varchar2(10)  path 'value[3]',
       country      varchar2(100) path 'value[4]'
    );Some docs about XMLTable and XML querying with Oracle :
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions228.htm#CIHGGHFB
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/xdb_xquery.htm#ADXDB1700
    Edited by: odie_63 on 24 juin 2010 20:07

  • Importing XML into oracle 11g database

    I am having some difficulty parsing an XML file into oracle 11g database.
    Currently using Oracle 11g Express Edition (XE)
    Here is how my XML file looks like:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <AccountMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    - <Accounts>
    - <AccountMapping>
    <AccountID>0000000000000-000</AccountID>
    <AccountName>XLS</AccountName>
    <AccountType>Excel</AccountType>
    <AccountOwner>System</AccountOwner>
    </AccountMapping>
    - <AccountMapping>
    <AccountID>0000000000000-001</AccountID>
    <AccountName>XLSS</AccountName>
    <AccountType>Excel2</AccountType>
    <AccountOwner>System2</AccountOwner>
    </AccountMapping>
    - <AccountMapping>
    and so on the file continues.. I have the xml file saved on my local hard disk
    I have created a package in SQL Developer
    create or replace
    PACKAGE XML_FILEHANDLER AS
    type TRecord is record (
    Account_ID varchar2(100)
    , AccountName varchar2(100)
    , AccountType varchar2(30)
    , AccountOwner varchar2(100)
    type TRecordTable is table of TRecord;
    function getRows (p_directory in varchar2, p_filename in varchar2) return TRecordTable pipelined;
    END XML_FILEHANDLER;
    -- BODY
    create or replace
    PACKAGE BODY XML_FILEHANDLER AS
    function getRows (p_directory in varchar2, p_filename in varchar2) return TRecordTable pipelined AS
    nb_rec NUMBER := 1;
    tmp_xml CLOB;
    tmp_file CLOB;
    rec TRecord;
    BEGIN
    dbms_lob.createtemporary(tmp_file, true);
    tmp_file := dbms_xslprocessor.read2clob(p_directory, p_filename);
    rec.Account_ID := regexp_replace(tmp_file, '.*<Account_ID>(.*)</Account_ID>.*', '\1', 1, 1, 'n');
    rec.AccountName := regexp_replace(tmp_file, '.*<AccountName>(.*)</AccountName>.*', '\1', 1, 1, 'n');
    rec.AccountType := regexp_replace(tmp_file, '.*<AccountType >(.*)</AccountType >.*', '\1', 1, 1, 'n');
    rec.AccountOwner := regexp_replace(tmp_file, '.*<AccountOwner>(.*)</AccountOwner>.*', '\1', 1, 1, 'n');
    loop
    -- this regexp finds occurrence(s) of this pattern : "<?xml ... ?><root_tag> ... </root_tag>"
    tmp_xml := regexp_substr(tmp_file, '<\?xml[^?]+\?>\s+<([^>]+)>.*?</\1>', 1, nb_rec, 'n');
    exit when length(tmp_xml) = 0;
    --dbms_output.put_line(tmp_rec);
    nb_rec := nb_rec + 1;
    SELECT Account_ID, AccountName, AccountType, AccountOwner
    into rec.Account_ID, rec.AccountName, rec.AccountType, rec.AccountOwner
    from xmltable(
    'Accounts/AccountMapping' passing xmltype(tmp_xml) columns
    Account_ID varchar2(100) path 'Account_ID'
    , AccountName varchar2(100) path 'AccountName'
    , AccountType varchar2(30) path 'AccountType'
    , AccountOwner varchar2(100) path 'AccountOwner'
    pipe row ( rec );
    end loop;
    dbms_lob.freetemporary(tmp_file);
    END getRows;
    END XML_FILEHANDLER;
    -- I am calling my function using the following sql query
    select * from table(XML_FileHandler.getRows('XML', 'test.xml'));
    Here is the error I am receiving
    ORA-29283: invalid file operation
    ORA-06512: at "SYS.UTL_FILE", line 536
    ORA-29283: invalid file operation
    ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 265
    ORA-06512: at "user.XML_FILEHANDLER", line 13
    29283. 00000 - "invalid file operation"
    *Cause:    An attempt was made to read from a file or directory that does
    not exist, or file or directory access was denied by the
    operating system.
    *Action:   Verify file and directory access privileges on the file system,
    and if reading, verify that the file exists.
    I have done the following
    - Provided appropriate access to user (read, write) including directory access rights
    - ensured that directory exists
    - ensured that file exists
    I have searched all over google and metalink but am unable to get this to run.. please help!

    >
    SELECT Account_ID, AccountName, AccountType, AccountOwner
    into rec.Account_ID, rec.AccountName, rec.AccountType, rec.AccountOwner
    from xmltable(
    'Accounts/AccountMapping' passing xmltype(tmp_xml) columns
    Account_ID varchar2(100) path 'Account_ID'
    , AccountName varchar2(100) path 'AccountName'
    , AccountType varchar2(30) path 'AccountType'
    , AccountOwner varchar2(100) path 'AccountOwner'
    >
    change to
    SELECT Account_ID, AccountName, AccountType, AccountOwner
    into rec.Account_ID, rec.AccountName, rec.AccountType, rec.AccountOwner
    from xmltable(
    'AccountMap/Accounts/AccountMapping' passing xmltype(tmp_xml) columns
    Account_ID varchar2(100) path 'Account_ID'
    , AccountName varchar2(100) path 'AccountName'
    , AccountType varchar2(30) path 'AccountType'
    , AccountOwner varchar2(100) path 'AccountOwner'
    SQL> SELECT Account_ID, AccountName, AccountType, AccountOwner
      2  --into rec.Account_ID, rec.AccountName, rec.AccountType, rec.AccountOwner
      3  from xmltable(
      4  'AccountMap/Accounts/AccountMapping' passing
      5  xmltype('<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
      6  <AccountMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      7  <Accounts>
      8  <AccountMapping>
      9  <AccountID>0000000000000-000</AccountID>
    10  <AccountName>XLS</AccountName>
    11  <AccountType>Excel</AccountType>
    12  <AccountOwner>System</AccountOwner>
    13  </AccountMapping>
    14  <AccountMapping>
    15  <AccountID>0000000000000-001</AccountID>
    16  <AccountName>XLSS</AccountName>
    17  <AccountType>Excel2</AccountType>
    18  <AccountOwner>System2</AccountOwner>
    19  </AccountMapping>
    20  </Accounts>
    21  </AccountMap>')
    22  columns
    23  Account_ID varchar2(100) path 'Account_ID'
    24  , AccountName varchar2(100) path 'AccountName'
    25  , AccountType varchar2(30) path 'AccountType'
    26  , AccountOwner varchar2(100) path 'AccountOwner'
    27  );
    ACCOUNT_ID                                                                       ACCOUNTNAME                                                                      ACCOUNTTYPE                    ACCOUNTOWNER
                                                                                     XLS                                                                              Excel                          System
                                                                                     XLSS                                                                             Excel2                         System2
    SQL> for AccountID use AccountID not Account_ID
    Account_ID varchar2(100) path 'AccountID'Edited by: AlexAnd on Aug 9, 2012 12:35 AM

  • Transform XML into Oracle

    Can anyone tell me how to transform data from XML file into Oracle DB without using any tool. I have not done it before.
    TIA,
    Geegee

    Not quite understand your question. But if you have an XML file and would like to store it into Oracle DB, you need to first create the DB Schema for accepting the data and using XSU to save it.
    If you would like to store it in single piece, just use CLOB. If you have Oracle9i, XMLType is also a good choice.

  • Loading Large XML into Oracle Database

    Hi,
    I am fairly new to XML DB. I have been successful in registering a schema to a table in the Database. Now, I have to load the appropriate XML into that table. I am using the Simple Bulk Loader program found on this oracle site, however, when I load my XML file I get the following error: ORA-21700: object does not exist or is marked for delete.
    So, I figured maybe simple bulk loader cannot handle large files? So I reduced my XML file and loaded it with the program and it worked. However, does anyone know how I can load large files into my registered schema table.
    Thanks,
    Prerna :o)

    Did you specify genTables true or false when registering the XML Schema ?
    Does you XML schema contain a recursive definition
    Is it possible that after reducing the size of the document you no longer have nodes that contain recursive structures...

  • Facing issue while reading XML file 'LPX-00217: '

    Hi Gurus,
    I am facing one issue while reading the xml file in the one my 11g database instance. The same file if I ran in another instance then it is working fine for me.
    I presume it will be related to NLS character. Please help me in finding out character set.
    And the issue where I am getting instance character set is 'US7ASCII', and I am not getting this issue in another instance where the character set is 'UTF8'.
    And here is the issue I am getting when I was trying to load that file.
    Error Occurred :=ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML
    processing
    LPX-00217: invalid character 150 (U+0096)
    Error at line 1
    Pls help me in debugging this issue.
    Regards,
    Nagendra
    Edited by: 838961 on Jul 12, 2011 9:32 PM

    Hi,
    Pls help me in debugging this issue.There's not much to debug actually.
    The US7ASCII charset stores 7-bit characters, but you're trying to insert a value out of range (150). So that's expected behaviour.
    There were some "tricks" to allow that on some versions, using NLS settings, but it's definitely not the clean way to do it so I won't develop.
    The best thing you have to do is to migrate to character set AL32UTF8, which is fully compliant with XML.

  • Reading XML from Oracle directory to generate charts

    Hi,
    I have a requirement create graphs, charts and maps based on data from a data warehouse (dw).  As I see things, there are two possibilities:
    Graphs, charts and maps based on an XML file
    Graphs, charts and maps based on Oracle tables
    Both would contain small data sets that will allow for quick response.  The intent of these graphs, charts and maps is to generate a dashboard that would allow the user to quickly drill down to the desired warehouse data.
    The proof of concept has already been validated using the Oracle table scenario.  My question is whether or not this could be accomplished reading xml files for generating the same set of dashboard items?
    My Oracle database and APEX environments configuration are as follows:
    NLSRTL                 11.2.0.1.0                                                           Production
    Oracle Database 11g Enterprise Edition 11.2.0.1.0                         64bit Production
    PL/SQL 11.2.0.1.0                                                                            Production
    TNS for Solaris: 11.2.0.1.0                                                               Production
    Application Express 4.2.2.00.11
    APEX Listener Release 2.0.2.  / Tomcat
    An Oracle database directory has been setup and is accessible to our APEX application.
    Any suggestions/help is appreciated.
    Thanks,
    Charles

    An Oracle Directory has an underlying OS directory associated with it, Oracle just overlays it's control structure onto an existing folder in the OS. You can manipulate the files with stored procedures in Oracle or at the OS level from outside of Oracle.
    If you manipulate the files from the OS level, outside of Oracle, you may need a refresh of the Oracle Directory structure.

  • Issue in Store XML into Schema generated tables and Validation XML against registered schema.

    Hello friends,
    I am facing some problem when store xml into generated tables from registered schema.
    This is my Schema
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.abc.inf.in/test" targetNamespace="http://www.abc.inf.in/test" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:include schemaLocation="abc.xsd"/>
      <xs:element name="project" type="student">
      <xs:annotation>
      <xs:documentation> This is a Documentation</xs:documentation>
      </xs:annotation>
      </xs:element>
    </xs:schema>
    -- This is my xml document
    <project versao="2.00" xmlns="http://www.abc.inf.in/test">
      <test xmlns="http://www.abc.inf.in/test">
      <intest version="2.00" Id="testabc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  >
      <ide>
      <cUF>35</cUF>
      <cNF>59386422</cNF>
      <natOp>this is post</natOp>
      <indPag>1</indPag>
      <mod>55</mod>
      <serie>1</serie>
      </ide>............
    Not giving full because it's too long.
    1. I Successfully registered Schema into database
    2. Then i generate table from registered Schema
    2. In my java code i validated XML document against Schema and it's successfully validate.
    3. But when i stored this XML into this generated table it's give me error
       Like :
    INSERT INTO XMLTABLE
    VALUES
    (XMLTYPE(bfilename('MYDIR','testabc.xml'),NLS_CHARSET_ID('AL32UTF8')))
    Error report:
    SQL Error: ORA-31061: XDB error: XML event error
    ORA-19202: Error occurred in XML processing
    LSX-00333: literal "94032000" is not valid with respect to the pattern
    And i have to store this xml into this tables so what i have to do ?

    Thanks for your reply odie_63.
    I got this my error solution. My XML document is not well structured based on my registered XML Schema.
    Means In My XML Document there are some invalid value and that not match my schema pattern so it's gives this error
    SQL Error: ORA-31061: XDB error: XML event error
    ORA-19202: Error occurred in XML processing
    LSX-00333: literal "94032000" is not valid with respect to the pattern
    For Solution we have two ways
    1. I have changed this literal "94032000" value in my xml file then save it.
    2.
    - We have to delete this schema then
    - we have to change Schema pattern for particular element
    like :--
    <xs:restriction base="xs:string">
      <xs:whiteSpace value="preserve"/>
      <xs:pattern value="[0-9]{3}"/>
    </xs:restriction>
    - then store xml into database it works..
    Thanks.

  • Import/insert data from XML into Oracle database tables?

    Hi. (I am using JDeveloper 10.1.3.3.0 and Oracle 10g)
    I have been able to export the data from one of my database tables by using a View Object and .writeXML.
    Now, I want to take an xml file that is formatted in the same way as what is spit out by the writeXML and put that info in my database table. I followed online examples and have tried using .readXML like so:
    Element element = XMLDoc.getDocumentElement();
    vo.readXML(element, -1);
    I know it is sort of working, because at first I got an error message that one of the required attributes was missing. So, I added that attribute to my xml file and ran my code. No errors. But, I checked my database, and the new records were not added.
    Is there something I have done wrong? Or is there perhaps something I left out? I also noticed there were several versions of readXML like readFromXML. Which one should I use and how?
    Thanks.

    KUBA, I changed my code to match your example:
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    File xmlFile = new File("C:/myfilehere.xml");
    Document doc = db.parse(xmlFile);
    Element element = doc.getDocumentElement();
    vo.readXML(element, -1);
    vo.getDBTransaction().commit();
    I still get no errors, but my database table has no new records.
    Any ideas why?
    Thanks.

  • Reading XML into a Hashtable

    I have the following XML file:
    <fields>
    <name>J. Postma</name>
    <date>21-05-2004</date>
    </fields>
    I want to put the fields in a Hashtable. Name is the key and "J. Postma" is the value. How can I parse the XML and add the fields into a Hashtable?

    Dubwai, me too. But for only a half-day of effort,
    you can make a few helper classes that vastly simplify
    the day-to-day usage of DOM.Yes. I've done that too. To the OP, if you use DOM, realize that the text value of a single element may be in multiple Text nodes. You can't just grab the first one. You need to loop through all Text node children and concatenate their values.

  • Is there a feature to load XML into Oracle 9 ?

    Hello,
    I receive some XML files containing error messages from an external vendor, so i want to load these files into my database, yet i never worked with xml for import, so i dont really know if oracle has a build in feature like sqlldr, that i could make use of.
    I run Solaris 5.8, so i could surely build a shellscript to do the job, as files are consistent. Just i wanted to use oracles tool, if there is any :)
    regards
    thva

    See e.g. XML DB FAQ

  • Issue inserting UTF8 data into Oracle in windows environment.

    I have a UTF8 PHP application that is writing a string containing special characters to oracle through a ODBC connection. The Oracle database is setup for UTF8 support.
    Here is the issue. I have a simple string, "louis de funès". When the data manually moved correctly in UTF8 the data comes up correctly. The Oracle dump() shows:
    WORKING DATA:
    String: louis de funès
    select keywords, dump(keywords, 17) from ame_links where keywords like '%louis de %';
    Typ=1 Len=15: l,o,u,i,s, ,d,e, ,f,u,n,c3,a8,s
    However, when the same string is Inserted through the PHP application the data shows up in the db like this.
    NOT - WORKING:
    String: louis de funès
    select keywords, dump(keywords, 17) from ame_links where keywords like '%louis de %';
    Typ=1 Len=17: l,o,u,i,s, ,d,e, ,f,u,n,c3,83,c2,a8,
    (The è character has 4 bytes associated with it)
    Windows Setup:
    Windows Registry: HKEY_LOCAL_MACHINE -> SOFTWARE -> ORACLE -> HOME0 ->
    NLS_LANG=AMERICAN_AMERICA.UTF8
    HTTP headers are set for Content-Type:text/html; charset=UTF-8.
    Anyone know why I would get 2 extra bytes (83,c2) added in the middle of the è character? Is the oracle client doing some other type of character set conversion before I insert it into the database.
    I have also noticed that when I change the NLS_LANG from AMERICAN_AMERICA.UTF8 to AMERICAN_AMERICA.WE8MSWIN1252 that the 4 byte 'è' character works and the 2 byte character doesn't.

    I reproduced the porblem. Only differnce from yours is that it reproduces regardless the NLS_LANG setting.
    Although I cannot be 100% sure, I think what is happening is that Microsoft ODBC Driver Manager converts the insert statement from Windows ACP to Unicode, then calls SQLExecDirectW (WideChar version of SQLExecDirect) of the Oracle ODBC Driver and passes the insert statement in Unicode. Since your PHP code passed the insert statement in UTF-8 encoding, and the Driver Manager converted it from Windows ACP to Unicode, the letter e with grave ("c3,a8" in UTF-8) was wrongly converted to U+00c3, U+00a8 in the Unicode insert statement, then converted to UTF8 ( "c3,83,c2,a8") by Oracle.
    By looking at the PHP source code, apparently PHP odbc_exec() function calls ANSI SQLExecDirect().
    I tried to verify that the Driver Manager calls SQLExecDirectW() of Oracle ODBC Driver by enabling the ODBC Tracing, but I couldn't make it work. It genetates an emply SQL.LOG file. So my investigation stops here.
    IF YOUR METADATA NAMES ARE ASCII ONLY, AND NON-ASCII CHARACTERS APPEAR ONLY IN DATA, you can workaround this problem by binding data. For example,
    $stmt = odbc_prepare($conn, "insert into AME_LINKS (keywords, site_id) values (?, ?)");
    $rs = odbc_execute($stmt, array($invar,77));
    Makoto

  • Need to Parse or Read XML into a ResultSet

    Hi, I see lots of examples of folks reading from a database, populating a ResultSet, and then putting that data into an XML document. I don't see any reference to going the other way, and was hoping some of you might have an insight on how to do this.
    We have a huge historical database and want to take the older info, put it into xml format, zip it, and store the zip'd result as a blob. That's the easy part.
    We want to be able to go back, to read the blob, unzip it, and then populate a ResultSet and return that to the caller. I don't see any slick methodology to either 1.) instantiate an empty ResultSet or 2.) parse/read an XML structure into a ResultSet.
    Any bright ideas?
    Thanks, John

    @maggie: That is easily done with XPath expressions, for example:
    xmlstarlet sel -t -m '//servers[@country_code="us"]' -c '.' -n vpn.xml
    xmlstarlet sel -T -t -m '//servers[@country_code="us"]' -v @public_name -o " " -v @bw -n vpn.xml
    xmlstarlet sel -t -m '//servers[@country_code="us"]' -v '@public_name' -o ": " -v '@currentload' -n vpn.xml
    xmlstarlet sel -t -m '//servers[@country_code="us" and @currentload<15]' -v '@public_name' -o ": " -v '@currentload' -n vpn.xml
    xmlstarlet sel -t -m '//servers[@currentload<15]' -v '@public_name' -o ": " -v '@currentload' -n vpn.xml
    http://www.w3schools.com/xpath/default.asp
    Edit: If you use json and jshon, then you'll have to do the sorting and filtering in the shell
    jshon -e servers -a -e country_code -u -p -e public_name -u -p -e bw -u <vpn.json | {
    # filter country_code
    while read -r country_code && read -r public_name && read -r bw; do
    [ x"$country_code" = x"ca" ] && echo "$public_name $bw";
    done
    } | sort -k2,2nr -k1,1d # sort second field (bw) numeric reverse, if equal use dictionary sort on first (name)
    Last edited by progandy (2015-05-31 05:47:50)

  • Error trying to insert xml into Oracle table

    Hi -
    I am trying to (a)read a row from emp table and output the results in xml format
    and (b) insert this row to another emp_new table (same structure as emp).
    When I run it here is what I get:
    OUTPUT IS:
    <?xml verions='1.0'?>
    <Employee>
    <Emp num="1">
    <EMPNO>7369</EMPNO>
    <ENAME>Smith</ENAME>
    <JOB>Clerk</JOB>
    <MGR>7902</MGR>
    <HIREDATE>12/7/1980</HIREDATE>
    <SAL>800</SAL>
    <DEPTNO>20</DEPTNO>
    </Emp>
    </Employee>
    Exception in thread "main" oracle.xml.sql.OracleXMLSQLException:
    No rows to modify -- the row enclosing tag is missing. Specify
    the correct row enclosing tag.
    etc...
    The row enclosing tag is given by setRowTag("Emp").
    What's wrong here? Any ideas?
    PS: To Ambrose Padilla: Your response was helpful. Thank you.
    Program
    import java.sql.*;
    import oracle.xml.sql.query.*;
    import oracle.jdbc.driver.*;
    import oracle.xml.sql.dml.*;
    class testXML
    public static void main(String[] args) throws SQLException
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    //initialize a JDBC connection
    Connecton conn = DriverManager.getConnection("jdbc:oracle:thin:mytest:1521:acme", "scott", "tiger");
    //initialize the OracleXMLQuery
    OracleXMLQuery qry =
    new OracleXMLQuery(conn,"select * from emp where rownum < 2");
         // set the document name
         qry.setRowsetTag("Employee");
         // set the row element name
         qry.setRowTag("Emp");
         // get the XML result
         String xmlString = qry.getXMLString();
         // print result
         System.out.println(" OUPUT IS:\n"+xmlString);
         OracleXMLSave sav = new OracleXMLSave(conn,"emp_new");
         sav.insertXML(xmlString);
         sav.close();
    }

    Try inserting
    sav.setRowTag("emp");
    before calling insertXML.

  • Read XML into the database

    Hi,
    If I have a XML file and want to read its attributes into matching columns in a table, what is the best way to map the xml e.g. firstname to a firstname column in the table?
    <name>
    <firstname>Bill</firstname>
    <last>Gates</last>
    </name>
    Thanks

    Why do you want to do this? (Might help with the answer).

Maybe you are looking for

  • Error at Migo of Stock Transfer.

    Hi Experts, During MIGO(Goods Receipt) against  STO(stock transfer Order)  of Finished Goods,  in previous date the message coming is :- MARC-VMTRA exceeded by 32.000 BOX : 49 DROO 0007 MFGPRODUCT 49 is material no droo is plant mfgproduct is split v

  • Hyperlinks in InDesign

    Does anyone know if there is a way in InDesign to create hyperlinks that will open a new browser window or tab?

  • Installed the new version itunes 10.3 and I got an error at the opening !

    I just installed the new 10.3 something of itunes and I got the error message "The iTunes Library.itl file is locked. It's located on a locked HD or you don't have sufficient priviledge to write for that file". I then click on the OK button. Now Itun

  • 8 year old ipod classic will not restore

    Tried it on two different computer, get the same message: error with the numbers., like 1429, 1439, etc.  Refered to that problem solving sheet, did everything it asked still won't restore. Chuck it or take it to apple store for repair? Thanks for an

  • Stop importing duplicate photos from camera using Bridge CS5?

    Hi, I'm having a few importing photo's using Bridge CS5,  as I'm on holidays at the moment I'm trying to keep my photo's on both my laptop as well as leaving a copy on the SD card of the camera (as a form of backup), however whenever I import photo's