Generation of XML files in oracle procedure

I have to generate a SQL query as XML files:

  • If the number of records in the query result exceeds 40 000 then the data must be divided into two XML files with different file names.

Following XML file format:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<EMP_INFO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <EMP>
  <CR_NO>12345678</CR_NO>
  <EMPLOYER_NAME>ABC</EMPLOYER_NAME>
  <ID_NO>12345678</ID_NO>
  <EMPLOYEE_NAME>ABC</EMPLOYEE_NAME>
  </EMP>
  <EMP>
  <CR_NO>12345678</CR_NO>
  <EMPLOYER_NAME>XYZ</EMPLOYER_NAME>
  <ID_NO>12345678</ID_NO>
  <EMPLOYEE_NAME>ABC</EMPLOYEE_NAME>
  </EMP>
</EMP_INFO>


  • Also, an XML file will contain information from XML file with the number of records in each file:
<?xml version="1.0" encoding="utf-8"?>
<Files>
  <File>
    <FileName>ABCD071120130001.xml</FileName>
    <CountOfRecords>499</CountOfRecords>
  </File>


  <File>
    <FileName>ABCD071120130002.xml</FileName>
    <CountOfRecords>9</CountOfRecords>
  </File>


</Files>


My PL SQL procedure follows, but throws an error:

CREATE OR REPLACE PROCEDURE P_DATAXML AS
BEGIN

  DECLARE
    XML_PROLOG    CLOB := '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
    xml_header    clob;
    xml_trailer   clob;
    tmp_xml       clob;
    tmp_file      clob;
  
    CURSOR C_REC IS  
    SELECT XMLELEMENT("EMP_INFO",
                            XMLELEMENT("CR_NO", "1234" ),
                            XMLELEMENT("EMPLOYER_NAME", "ABC" ),
                            XMLELEMENT("ID_NO", "9876541" ),
                            XMLELEMENT("EMPLOYEE_NAME", "XYZ" )
             ).GETCLOBVAL() AS DATA_XML
           
      FROM TABLES;
  
  BEGIN

    -- create the temporary clob :
    DBMS_LOB.CREATETEMPORARY(TMP_FILE, TRUE);
  
    -- fetch records
    for r in C_REC loop
      DBMS_LOB.append(TMP_FILE, xml_prolog);
      DBMS_LOB.append(TMP_FILE, r.DATA_XML);
    end loop;


    -- write file to directory :
    dbms_xslprocessor.clob2file(TMP_FILE, 'CDIR', 'test.xml', nls_charset_id('AL32UTF8'));
    dbms_lob.freetemporary(TMP_FILE);

  END;

END P_DATAXML;


After my initial coding, I get the error made his first appearance on "dbms_xslprocessor.clob2file":

ORA-21560: 3 argument is null, invalid or out of range

ORA-06512: at "SYS." DBMS_LOB", line 991

ORA-06512: at "XDB". DBMS_XSLPROCESSOR', line 324

What could be wrong?

You were on the right track. Continue to use SQL/XML, in special XML files XMLAGG logical global functions.

The following should answer your initial needs.

For this demonstration, I used resources. Table EMPLOYEES and a batch size of 100. It generates three files, 'file0001.xml' (100 records), "file0002.xml" (7 records) and a summary file:

DECLARE

file_desc_array xmlsequencetype: = xmlsequencetype();

CLOB file_desc_xml;

prolog1 CLOB: = '';

prolog2 CLOB: = '';

BEGIN

for r in)

Select xmlserialize (document

XmlElement ('method'

, xmlattributes ("http://www.w3.org/2001/XMLSchema-instance" under the name "xmlns: xsi" "")

xmlagg)

XmlElement ("EMP"

xmlelement ("ID_NO", e.employee_id)

, xmlelement ("EMPLOYEE_NAME", select)

)

)

)

) as xmldoc

--< generating="" summary="" record="">

xmlelement ("file",

xmlelement ("filename",

, "file" | TO_CHAR (trunc ((rownum-1)/100) + 1, "fm0999"). ".xml".

)

xmlelement ("CountOfRecords", Count

) as file_desc

-->

, "file" | TO_CHAR (trunc ((rownum-1)/100) + 1, "fm0999"). '.xml' as file name

of e hr.employees

Group of trunc ((rownum-1)/100)

)

loop

dbms_xslprocessor.clob2file (prolog1 | r.xmldoc, 'TEST_DIR', r.filename, nls_charset_id ('AL32UTF8'));

file_desc_array.extend;

file_desc_array (file_desc_array. (Last): = r.file_desc;

end loop;

Select xmlserialize (document

XmlElement ("Files", xmlagg (column_value))

)

in file_desc_xml

table (file_desc_array);

dbms_xslprocessor.clob2file (prolog2 | file_desc_xml, 'TEST_DIR', 'summary.xml', nls_charset_id ('AL32UTF8'));

END;

/

Tags: Database

Similar Questions

  • Load the XML file into oracle DB using OWB

    Hi friends,

    I'm new XML data.
    I had a requirememnt to load the xml file into an oracle table.
    Can someone procedure to load the data.

    Thanks in advance

    see this

    http://blogs.Oracle.com/warehousebuilder/2007/09/leveraging_xdb.html

  • Load the XML file into Oracle external Table


    I load the data from the XML file into an intermediate table Oracle using external Tables.

    Let's say below, it is my XML file

    < header >
    < A_CNT > 10 < / A_CNT >
    < E_CNT > 10 < / E_CNT >
    < AF_CNT > 10 < / AF_CNT >
    < / header >
    < student >
    <>students-details
    < Student_info >
    < Single_Info >
    < ID > 18 / < ID >
    New York < City > < / City >
    < country > United States < / country >
    < Name_lst >
    < Student_name >
    Samuel < name > < / name >
    Paul < Last_name > < / Last_name >
    < DOB > 19871208 < / DOB >
    Aware of < RecordStatus > < / RecordStatus >
    < / Student_name >
    < Student_name >
    Samuel < name > < / name >
    Paul < Last_name > < / Last_name >
    < DOB > 19871208 < / DOB >

    < TerminationDt > 20050812 < / TerminationDt >
    History of < RecordStatus > < / RecordStatus >
    < / Student_name >
    < / Name_lst >
    < Personal_Info >
    <>men < / Type >
    < 27 > < / Age >
    < / Personal_Info >
    < / Single_Info >
    < / Student_info >

    < student - register >
    class < A >
    < info >
    < detail >
    < ID student > 18 < / student >
    EE < major > < / Major >
    < course-Grades >
    < course > VLSI < / course >
    < degree > 3.0 < / Grade >
    < / course-Grades >
    < course-Grades >
    < course > nanotechnology < / course >
    < degree > 4.0 < / Grade >
    < / course-Grades >
    < / details >
    < detail >
    < ID student > 18 < / student >
    THIS < major > < / Major >
    < / details >
    < / info >
    class < A >
    < Student_Enrol >
    <>students-details
    < student >

    I load this XML data file into a single table using an external Table. Could someone help me please with coding.

    Thank you

    Reva

    Could you please help me how to insert my XML content into that.

    Same as before, try a plain old INSERT:

    insert into xml_pecos

    values)

    XmlType (bfilename ('XML_DIR', "test.xml"), nls_charset_id ('AL32UTF8'))

    );

    But you'll probably hit the same limitation as with the binary XMLType table.

    In this case, you can use FTP to load the file as a resource in the XML DB repository.

    If the XML schema has been registered with the hierarchy enabled then the file will be automatically inserted into the table.

    Could you post the exact statement that you used to save the scheme?

    In the meantime, you can also read this article, I did a few years ago, it covers the XML DB features that may be useful here, including details on how to load the file via FTP:

    https://odieweblog.WordPress.com/2011/11/23/Oracle-XML-DB-a-practical-example/

    And documentation of the course: http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb06stt.htm#ADXDB4672

  • Problem with the date when you load the XML file into Oracle Database 10g

    Hi all

    I have the interface as shown in the screenshot below. In this document, among other things, I am mapping to an element XML file representing a date to an Oracle table column defined as DATE. The source and target columns are highlighted in the screenshot.

    ! http://img223.imageshack.us/img223/1565/odiscr275.jpg!

    When I run the interface, I get the following error message:

    java.lang.IllegalArgumentException to java.sql.Date.valueOf(Date.java:103)

    I guess that this is the conversion of the date!

    I already tried to replace SRC_TRADES. DEAL_DATE with TO_DATE (SRC_TRADES. DEAL_DATE, ' DD/MM/YYYY') on the implementation tab. This feature was not recognized when I executed the interface, so it did not work! The value of date in the XML file is in the format DD/MM/YYYY .

    I guess that Date SQL Oracle functions do not work in the implementation tab. Could someone let me know:

    1. what the Date Conversion function I could use instead?
    2. where can I find a reference to the methods/functions that I use in the implementation tab (if such a reference exists)?

    See you soon.

    James

    Hello.

    Try changing the area of execution at the staging area. Once you change it, write in the map box just SRC_TRADERS. DEAL_DATE. When you use TO_DATE, the source field typu should be varchar2, no date (as it is in store for your data source)

  • Load the XML file into oracle using sql loader

    Hello

    I'm trying to load an xml file into a table using sqlldr.
    I have a table as follows:
    CREATE TABLE xmlloadtable
    ( id number,
     data_xml XMLType
     )
      XmlType data_xml STORE AS CLOB;
    I have a control file that I know is perfectly false:
    LOAD DATA 
    INFILE '/home/oraread/'
    INTO TABLE xmlloadtable 
    (
    id,
    data_xml 
    )
    I googled for the file control and tried in different ways, but of no use.
    I want to load the entire xml file into the table.
    Can someone help me with the correct control file. Any help is appreciated!

    Try this

    LOAD DATA
    INFILE '/home/oraread/'
    INTO TABLE xmlloadtable
    (id,
     file_name          filler,
     data_xml          lobfile(file_name) terminated by eof
    )
    

    You can add the file as a column name field to your table between the id and xml column and remove the word to fill in the .ldr file if you need to keep the name of the file

  • How to create the xml file in oracle plsql

    Hello

    I need the under xml (abc.xml) in unix Server out_directory file (the out_directory path: / u01/apps/xml /)

    Select sivauser, sivapwd from sivainformations;-it will be multiple records

    Select sivatelepone phone; - it will be multiple records

    Select xyzverion versionid; - it will be multiple records

    based on the above information, I need the sub file xml using oracle plsql procedure or a block

    example: suppose we record

    <? XML version = "1.0" encoding = "UTF-8"? >
    "< sivaService version ="2.0"xmlns ="http://www.siva.ab/siva/4.0/test">."
    < data language 'DEU' = >
    < sivauser action = "siva3" sivapwd = "siva123" > --i need to sivainformations table(sivauser,sivapwd) timeline
    phone < sivatelepone > < / sivatelepone >--i need to chronogram sivatelepone table (phone) based on the sivauser column
    < abcversion version = "1.0" >
    < Productinfo >
    versionID < xyzverion > < / xyzverion >--i need to xyzverion (versionid) based on the sivauser column table records
    < / Productinfo >
    < / abcversion >
    < / action >
    < / data >
    < / sivaService >


    example: assume that multiple records

    <? XML version = "1.0" encoding = "UTF-8"? >
    "< sivaService version ="2.0"xmlns ="http://www.siva.ab/siva/4.0/test>
    < data language 'DEU' = >
    < sivauser action = "siva3" sivapwd = "siva123" > --i need to sivainformations table(sivauser,sivapwd) timeline
    < sivatelepone > '345678' < / sivatelepone >--i need to chronogram sivatelepone table (phone) based on the sivauser column
    < abcversion version = "1.0" >
    < Productinfo >
    '1.1' < xyzverion > < / xyzverion >--i need to xyzverion (versionid) based on the sivauser column table records
    < / Productinfo >
    < / abcversion >
    < / action >

    < sivauser action = "siva4" sivapwd = "siva123" > --i need to sivainformations table(sivauser,sivapwd) timeline
    < sivatelepone > '123456' < / sivatelepone >--i need to chronogram sivatelepone table (phone) based on the sivauser column
    < abcversion version = "1.0" >
    < Productinfo >
    "1.2" < xyzverion > < / xyzverion >--i need to xyzverion (versionid) based on the sivauser column table records
    < / Productinfo >
    < / abcversion >
    < / action >
    < / data >
    < / sivaService >

    Please help me

    Thank you
    Siva

    I added a column ID to match the lines between the three tables.

    SQL> with sivainformations
      2  as
      3  (
      4     select 1 id, 'karthick' sivauser, 'karthick' sivapwd from dual union all
      5     select 2 id, 'ram', 'ram' from dual
      6  )
      7  , sivatelepone
      8  as
      9  (
     10     select 1 id, 1234567890 telepone from dual union all
     11     select 2 id, 1234512345 from dual
     12  )
     13  , versionid
     14  as
     15  (
     16     select 1 id, 1.1 versionid from dual union all
     17     select 2, 1.2 from dual
     18  )
     19  select xmlelement
     20         (
     21             "shivaService"
     22           , xmlattributes('2.0' as "version", 'http://www.siva.ab/siva/4.0/test' as "xmlns")
     23           , xmlelement
     24             (
     25                 "Data"
     26               , xmlattributes('DEU' as "language")
     27               , xmlagg
     28                 (
     29                     xmlelement
     30                     (
     31                          "Action"
     32                        , xmlattributes(s.sivauser as "sivauser", s.sivapwd as "sivapwd")
     33                        , xmlelement("shivatelepone", t.telepone)
     34                        , xmlelement
     35                          (
     36                              "abcversion"
     37                            , xmlattributes('1.0' as "version")
     38                            , xmlelement
     39                              (
     40                                   "ProductInfo"
     41                                 , xmlelement("xyzversion", v.versionid)
     42                              )
     43                          )
     44                      )
     45                 )
     46             )
     47         ).EXTRACT('*') xml_output
     48    from sivainformations s
     49    join sivatelepone t
     50      on s.id = t.id
     51    join versionid v
     52      on s.id = v.id;
    
    XML_OUTPUT
    -------------------------------------------------------------------------------------------------------------------
    
      
        
          1234567890
          
            
              1.1
            
          
        
        
          1234512345
          
            
              1.2
            
          
        
      
    
    
    SQL>
    
  • Question to load the XML file into Oracle via ODI: LKM and IKM adjustment

    Hi all

    I am currently building an ODI interface to upload my file system XML local in a 10 g to Oracle database.

    I received the error message shown in the screenshot below:

    ! http://img529.imageshack.us/img529/3491/odiscr175.jpg!

    The main problem I have is, I don't know all what LKM or IKM assign.

    Can someone offer any assistance/advice?

    Thanks in advance.

    James

    James
    You must select the LKM SQL for Oracle (or LKM SQL for SQL) and then within Oracle to integrate Oracle the IKM incremental update or append IKM SQL command.
    Reading XML, you can just use the standard SQL KMs. (when writing, there's a little more necessary artifice, and this can be done by using specific IKMs)
    Hope this helps

  • Import large XML file to Table

    I have a large (819 MB) XML file I'm trying to import into a table format:
    < ROW_SET >
    < ROW >
    value of < column_name > < / nom_de_colonne >
    < / ROW >
    ...
    < ROW >
    value of < column_name > < / nom_de_colonne >
    < / ROW >
    < / ROW_SET >

    I tried to import with xmlsequence (...). Extract (...) and ran into the number of nodes exceeds maximum error.

    I tried to import with XMLTable (... from XMLTYPE (bfilename('DIR_OBJ','large_819mb_file.xml'), nls_charset_id('UTF8'))) and I gave up after he had run for 15 + hours (COLLECTION ITERATOR PICKLER FETCH number).

    I tried to import them with:

    insCtx: = DBMS_XMLStore.newContext ('schemaname.tablename');
    DBMS_XMLStore.clearUpdateColumnList (insCtx);
    DBMS_XMLStore.setUpdateColumn (insCtx, 'column1name');
    ...
    DBMS_XMLStore.setUpdateColumn (insCtx, 'columnNname');
    LINES: = DBMS_XMLStore.insertXML (insCtx, XMLTYPE (bfilename('DIR_OBJ','large_819mb_file.xml'), nls_charset_id ('UTF8')));

    and ran in ORA-04030: lack of memory of process when trying to allocate 1032 bytes (subheap qmxlu, qmemNextBuf:alloc).


    All I have to do is read the XML file and move the data into a table in a reasonable time. Once I have given in the database, no longer need the XML file.

    What would be the best way to import large XML files?


    Oracle Database 11 g Release 11.2.0.1.0 - 64 bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    "CORE 11.2.0.1.0 Production."
    AMT for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production

    (Gross) approach should work for you.

    CREATE TABLE HOLDS_XML
            (xml_col XMLTYPE)
          XMLTYPE xml_col STORE AS SECUREFILE BINARY XML;
    
    INSERT INTO HOLDS_XML
    VALUES (xmltype(bfilename('DIR_OBJ','large_819mb_file.xml'), nls_charset_id('UTF8')))
    -- Should be using AL32UTF8 for DB character set with XML
    
    SELECT ...
      FROM HOLD_XML HX
           XMLTable(...
              PASSING HX.xml_col ...)
    

    How it differs from your approach.

    With the help of the HOLDS_XML table with storage XML BINARY SECUREFILE (which become the default in 11.2.0.2), we provide a place for Oracle store a parsed version of the XML data. This allows the XML code to be stored on the disk instead of memory. Oracle can then access the necessary XML fragments of the disc in the instead holding the entire XML in memory and the analysis several times to find the necessary information. That's what COLLECTION ITERATOR PICKLER FETCH means. A lot of memory. You can search on this term to learn more about this if necessary.

    The approach XMTable then simply reads this XML to disk file and should be able to parse the XML without problem. You have the option to add XML indexes, but since you read just a while and throw it away, there is no advantage to (most likely) index

  • Creating Oracle's XML files in a directory

    Hi all

    I was going through the concepts Oracle XMLDB and discovered that we can create an XML file using the instructions normal select.

    Now, I create an Oracle Directory that points to the remote Unix computer.

    I want to know if we can create this XML file in the directory that points to the remote Unix directory.

    I don't want to use here the concepts of coil or UTL_FILE.


    Receive your answer on that.

    Thank you
    Madhu K.

    I'm not sure of your condition. However, here are a few example file writing Oracle's XML to disk.

    SQL> drop table test_clob;
    
    Table dropped.
    
    SQL> CREATE TABLE test_clob (id INTEGER,clob_col CLOB);
    
    Table created.
    SQL> ed
    Wrote file afiedt.buf
    
      1  INSERT INTO test_clob VALUES(1,'
      2  
      3  
      4  AAA
      5  godknows
      6  xyz
      7  
      8  
      9  BBB
     10  something
     11  zbc
     12  
     13  
     14  CCCC
     15  whoknows
     16  mon
     17  
     18* ')
    SQL> / 
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> DECLARE
      2   v_xml                 XMLTYPE ;
      3    v_doc                 XMLDOM.DOMDocument;
      4    v_dir                 VARCHAR2(2000);
      5    v_file                VARCHAR2(2000);
      6  BEGIN
      7    v_dir := 'TEST_DIR';
      8    v_file := 'emp.xml'; -- name of the output file
      9    SELECT xmltype(clob_col)
     10    INTO v_xml
     11    FROM test_clob
     12    WHERE id=1;
     13    v_doc := DBMS_XMLDOM.NEWDOMDOCUMENT(v_xml);
     14    DBMS_XMLDOM.WRITETOFILE(v_doc, v_dir||'\'||v_file, 'UTF-8');
     15    DBMS_XMLDOM.FREEDOCUMENT(v_doc);
     16  END;
     17  / 
    
    PL/SQL procedure successfully completed.
    
    SQL>
    

    - and the generated file:

    C:\>type emp.xml
    
    
      
        AAA
        godknows
        xyz
      
      
        BBB
        something
        zbc
      
      
        CCCC
        whoknows
        mon
      
    
    
    C:\>
    

    Another way:

    ---------------------------------------------------------
    SQL> DECLARE
      2    v_clob   CLOB := EMPTY_CLOB;
      3    v_amount INTEGER;
      4    /*** Curtesy to odie_63 ***/
      5    CURSOR cur_crl IS
      6      SELECT xmltype(response_file, nls_charset_id('CHAR_CS')).getclobval() rfile
      7               FROM clarity_response_log;
      8   /***************/
      9  BEGIN
     10    dbms_lob.createtemporary(v_clob, TRUE);
     11    FOR i IN cur_crl LOOP
     12      v_amount := DBMS_LOB.GETLENGTH(i.rfile);
     13      Dbms_LOB.WRITEAPPEND(v_clob, v_amount, i.rfile);
     14      v_amount := DBMS_LOB.GETLENGTH(CHR(10));
     15      Dbms_LOB.WRITEAPPEND(v_clob, v_amount, CHR(10)); --This is for Line break.
     16    END LOOP;
     17
     18    DBMS_XSLPROCESSOR.CLOB2FILE(cl      => v_clob,
     19                                flocation => 'TEST_DIR',
     20                                fname     => 'response.xml',
     21                                csid      => 0);
     22  END;
     23  / 
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • File XML processing in oracle

    Hello

    I have the following provision in the xml:

    < csg >
    < ecrminput id = '000000001' >
    < xml id = "001" title = "CustomerId" > blah blah blah < / xml >
    < xml id = "002" title = "ContactId" > blah blah blah < / xml >
    < xml id = '003' title = "CustomerNo" > blah blah blah0 < / xml >
    < xml id = "500" title = "Attribute" > blah blah blah < / xml >
    < xml id = "500" title = "Attribute" > blah blah blah < / xml >
    < xml id = "1027" title = "Booking Code" > blah blah blah < / xml >
    < xml id = "1028" title = "Payment Reference" > blah blah blah < / xml >
    < xml id = "1029" title = 'Number of buyer' > blah blah blah < / xml >
    < / ecrminput >
    < ecrminput id = "000000002" >
    < xml id = "001" title = "CustomerId" > blah blah blah < / xml >
    < xml id = "002" title = "ContactId" > blah blah blah < / xml >
    < xml id = "500" title = "Attribute" > blah blah blah < / xml >
    < xml id = "500" title = "Attribute" > blah blah blah < / xml >
    < xml id = "1027" title = "Booking Code" > blah blah blah < / xml >
    < xml id = "1028" title = "Payment Reference" > blah blah blah < / xml >
    < xml id = "1029" title = 'Number of buyer' > blah blah blah < / xml >
    < xml id = "1016" title = "Call-ID" > blah blah blah < / xml >
    < / ecrminput >
    < / csg >

    and I need to find the best way to load this in oracle and extract the node information. The solution I came up with that is to load the xml document into a table with the field of clob, then extracted using a similar like syntax type below:

    SELECT a.*,
    DBMS_LOB. InStr (XmlType.getclobval (Attribute),' > AUGUST < ')
    from (SELECT extractvalue (value (xml_sequence) "," ecrminput/xml[@title="CustomerId"]') CustomerId,)
    Extract (value (xml_sequence) "," ecrminput/xml[@title="Attribute"]'), attribute
    OF xml_lfc donnees_xml,.
    table (XMLSequence (Extract (XmlType (xml_DATA), ' / csg/ecrminput "))) xml_sequence);

    This works when the file is small, but I need load and process a file more 6 000 000 records as part of the initial charge.

    Any ideas? I tried going down the road of xmlschema, but the xml file can have different fields of each record and the < xml = "500" title = "Attribute" id > tag may be repeated several times for each record also.

    Return of 1,000 records using the syntax above takes about 60 seconds. I use this on oracle 10g so am not able to use the index for xmltypes stuff.

    See you soon.

    Published by: user7989950 on July 7, 2010 23:48

    Published by: user7989950 on July 7, 2010 23:53

    Here's a starter DBMS_XMLDOM for you to have a game with...

    declare
      v_xml XMLTYPE := XMLTYPE('
    
    blah blah blah
    blah blah blah
    blah blah blah0
    blah blah blah
    blah blah blah
    blah blah blah
    blah blah blah
    blah blah blah
    
    
    blah blah blah
    blah blah blah
    blah blah blah
    blah blah blah
    blah blah blah
    blah blah blah
    blah blah blah
    blah blah blah
    
    ');
      v_xsdoc     DBMS_XMLDOM.DOMDocument;
      v_dn        DBMS_XMLDOM.DOMNode;
    
      PROCEDURE processnode; -- forward declaration
    
      PROCEDURE processattributes IS
        nm                      DBMS_XMLDOM.DOMNamedNodeMap;
        attr                    DBMS_XMLDOM.DOMAttr;
        attnode                 DBMS_XMLDOM.DOMNode;
        attname                 VARCHAR2(50);
        attval                  VARCHAR2(250);
      BEGIN
        nm := DBMS_XMLDOM.GetAttributes(v_dn);
        FOR i IN 0..DBMS_XMLDOM.GetLength(nm)-1
        LOOP
          attnode := DBMS_XMLDOM.Item(nm, i);
          attr := DBMS_XMLDOM.MakeAttr(attnode);
          attname := DBMS_XMLDOM.GetName(attr);
          attval := DBMS_XMLDOM.GetValue(attr);
          dbms_output.put_line('Attribute: '||attname||' Value: '||attval);
        END LOOP;
      END;
    
      PROCEDURE parse_node_element IS
        eltype        VARCHAR2(100);
      BEGIN
        eltype := DBMS_XMLDOM.GetTagName(DBMS_XMLDOM.MakeElement(v_dn));
        dbms_output.put_line('Tag: '||eltype);
        processattributes;
        processnode;
      END;
    
      PROCEDURE parse_node_text IS
      BEGIN
        DBMS_OUTPUT.PUT_LINE('Text: '||DBMS_XMLDOM.GetNodeValue(v_dn));
      END;
      PROCEDURE processnode IS
        dnl      DBMS_XMLDOM.DOMNodeList;
        nt       PLS_INTEGER;
      BEGIN
        dnl := DBMS_XMLDOM.GetChildNodes(v_dn);
        dbms_output.put_line('Child Nodes Found: '||DBMS_XMLDOM.GetLength(dnl));
        IF NOT DBMS_XMLDOM.IsNull(dnl) THEN
          FOR i IN 0 .. (DBMS_XMLDOM.GetLength(dnl) - 1)
          LOOP
            v_dn := DBMS_XMLDOM.Item(dnl, i);
            nt := DBMS_XMLDOM.GetNodeType(v_dn);
            CASE
              WHEN nt = DBMS_XMLDOM.ELEMENT_NODE THEN
                parse_node_element;
              WHEN nt IN (DBMS_XMLDOM.TEXT_NODE) THEN
                parse_node_text();
            ELSE
              NULL; -- Unhandled node type;
            END CASE;
          END LOOP;
        END IF;
      END;
    BEGIN
      v_xsdoc := DBMS_XMLDOM.NewDOMDocument(v_xml);
      v_dn := DBMS_XMLDOM.GetFirstChild(DBMS_XMLDOM.MakeNode(v_xsdoc)); -- 
      processnode;
    END;
    

    Currently, who's out like that...

    Child Nodes Found: 2
    Tag: ecrminput
    Attribute: id Value: 000000001
    Child Nodes Found: 8
    Tag: xml
    Attribute: id Value: 001
    Attribute: title Value: CustomerId
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 002
    Attribute: title Value: ContactId
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 003
    Attribute: title Value: CustomerNo
    Child Nodes Found: 1
    Text: blah blah blah0
    Tag: xml
    Attribute: id Value: 500
    Attribute: title Value: Attribute
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 500
    Attribute: title Value: Attribute
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 1027
    Attribute: title Value: Reservation Code
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 1028
    Attribute: title Value: Payment Reference
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 1029
    Attribute: title Value: Purchaser Customer Number
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: ecrminput
    Attribute: id Value: 000000002
    Child Nodes Found: 8
    Tag: xml
    Attribute: id Value: 001
    Attribute: title Value: CustomerId
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 002
    Attribute: title Value: ContactId
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 500
    Attribute: title Value: Attribute
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 500
    Attribute: title Value: Attribute
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 1027
    Attribute: title Value: Reservation Code
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 1028
    Attribute: title Value: Payment Reference
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 1029
    Attribute: title Value: Purchaser Customer Number
    Child Nodes Found: 1
    Text: blah blah blah
    Tag: xml
    Attribute: id Value: 1016
    Attribute: title Value: Call ID
    Child Nodes Found: 1
    Text: blah blah blah
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • How can store a very large file in Oracle XML DB?

    Hello
    I m looking for a quick way to store an XML file to an oracle 10 g XE. I was trying to store the file of 500 KB in the database as an xmltype or a clob, but I still have the same error: "ORA-01704: string literal too long." I m looking for a long time the possibility to store this file and one other (113 MB) in the database. I had sought by google to see if there is no solution, and the unique solution is to splitt the document in a loop (due to the limit of 32 KB) instruction. But this solution Don t allow storage with an XML schema and must slow down.
    Here is an example how I did it (but it didn t work):
    create table world (Nr int. xmldata xmltype);
    INSERT INTO global VALUES (1, 'big xml file');
    I would also try the alternative with a variable binding as follows:
    create or replace PROCEDURE ProcMondial IS
    poXML CLOB.
    BEGIN
    poXML: = 'large xml file ";
    INSERT INTO the world of the VALUES (1, XMLTYPE (poXML));
    EXCEPTION
    WHILE OTHERS THEN
    raise_application_error (-20101, ' Exception occurred in the :'|| global procedure) SQLERRM);
    END ProcMondial;
    I'm also getting the same error: long chain!
    I use developer sql for the query.
    Please help me, I m desperate.
    Thank you!

    Michael

    This should help
    {: identifier of the thread = 887934}

  • How can I transfer content from an XML file in a MS SQL database of the stored procedure using LabWindows/CVI SQL Toolkit?

    Hello

    I have a problem to transfer content to an XML file in a MS SQL database through a stored procedure data/fixed. I am able to transfer the content of the file using method...

    HSTMT = DBPrepareSQL (hdbc, EXEC usp_InsertReport " ... ");

    resCode = DBExecutePreparedSQL (hstmt);

    resCode = DBClosePreparedSQL (hstmt);

    ... but in this case, I am not able to read the return value of the stored procedure.

    I tried to follow the example of the stored procedure in the help documentation (DBPrepareSQL), but I miss a xml data type?

    No idea how to solve my problem?

    Cake of KR

    DianaS salvation,

    Thanks for your comments. During this time I found another way which fullfill my needs:

    resCode = DBSetAttributeDefault (hdbc, ATTR_DB_COMMAND_TYPE, DB_COMMAND_TEXT);

    sprintf (sz_SqlStatement, "DECLARE @TESTID INT EXEC @TESTID = usp_InsertReport ' SELECT 'RetVal' %s = @TESTID", sz_Buffer ");
    HSTMT = DBActivateSQL (hdbc, sz_SqlStatement);

    While ((resCode = DBFetchNext (hstmt)) == DB_SUCCESS)

    {

    / * Enter values in the record. */

    resCode = DBGetColInt (hstmt, 1, & s32_TestId);
    }

    resCode = DBDeactivateSQL (hstmt);

    sz_Buffer is the content of the XML file.

    Cake of KR

  • Oracle 12 c (12.1.0.1): joint audit with audit_trail = XML mode, no check XML file generated

    Hello

    Working on a new installation of Oracle 12 c EE (12.1.0.1) in RHEL 6.5 environment: joint audit mode (unified audit trail is turned on) and audit_trail = XML.

    However, no verification of the XML files are generated in audit_file_dest.  What additional configuration is required to use audit_trail = XML in joint audit mode?

    Hello

    If you enable audit unified, that is no longer the mixed mode, mixed mode, that's what you get by default, once you enable the unified audit all audit records will share the internal unified audit trail and xml audit is no longer works (essentially audit_trail parameter is ignored).

    Greetings,

    Damage ten Monkshood

  • How to create the script to compile procedure files in oracle - urgent deadline...

    How to create the script to compile procedure files in oracle.    about to go live and have much .prc pkg in a directory usr/tmp/ar... Po... human resources etc. need to create a script to compile all the files in the folder, then do not open all necessary .prc suggestions on how to do it.   Thank you Tom.

    (1) an urgent need, ASAP,... are words that do not in a forum of volunteer. We are here to help if you need it now, for free, open a SR.

    (2) oracle procedures are not files.

    (3) I think you are trying to run operating system packages, no Oracle procedure. right?

  • Generate the XML file with elements and attributes in table Oracle

    Hello

    I have the following table structure.

    CREATE TABLE SPOOL
    (
    COIL_ID NUMBER (10),
    COIL_NUMBER VARCHAR2 (40),
    COIL_PO_OPERATING_UNIT VARCHAR2 (20).
    COIL_PO_NUMBER VARCHAR2 (40),
    MILL_NUMBER VARCHAR2 (2),
    MILL_COIL_STATUS VARCHAR2 (15).
    ITEM_NUMBER VARCHAR2 (40),
    COIL_WEIGHT NUMBER (38),
    WEIGHT_UOM VARCHAR2 (10),
    DOCUMENT_NUMBER VARCHAR2 (40),
    DATE OF DOCUMENT_DATE,
    DOCUMENT_STATUS VARCHAR2 (15).
    DOCUMENT_TYPE VARCHAR2 (20).
    DOCUMENT_SOURCE VARCHAR2 (20).
    TEST_ID NUMBER (38),
    NUMBER VALUE,
    TEST_UOM VARCHAR2 (20).
    TEST_STATUS VARCHAR2 (70).
    TESTER_LOGIN VARCHAR2 (20).
    EQUIPMENT_CODE VARCHAR2 (50).
    DOC_STS_MSG VARCHAR2 (600)
    )
    /
    For each record COILID, there could be several folders baased on TEST_ID/VALUE/TEST_UOM etc.

    And I would like to prepare the xml file in the following format by selecting data in the COIL?


    <? XML version = "1.0"? >
    -coil xsi: noNamespaceSchemaLocation = "www.tempel.com/COIL.xsd" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:xdb = "http://xmlns.oracle.com/xdb" >
    < CoilId > 1419532 < / CoilId >
    < CoilNo > D2221050010A0 < / CoilNo >
    Changzhou < CoilPOOperatingUnit > < / CoilPOOperatingUnit >
    < CoilPONo > 4619 < / CoilPONo >
    < MillNo > 86 < / MillNo >
    Test of < MillCoilStatus > < / MillCoilStatus >
    C5 050FP800 < ItemNo > < / ItemNo >
    < weight > 7076 < / weight >
    KILOGRAM of < GLU > < / UDM >
    < DocumentNo > 0 < / DocumentNo >
    < DocumentDate > 2013 - 01 - 11 < / DocumentDate >
    < DocumentStatus > not < / DocumentStatus >
    < DocumentType > test < / DocumentType >
    CHIGMA1 < DocumentSource > < / DocumentSource >
    < DocStsMsg test = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "0.4992" TestUnit = "mm" Status = 'NonProcessed' TestId = "135" / >
    < test DocStsMsg = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "0.0128" TestUnit = "mm" Status = 'NonProcessed' TestId = "124" / >
    < DocStsMsg test = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "12" TestUnit = "mm" Status = 'NonProcessed' TestId = "125" / >
    < DocStsMsg test = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "0.5095" TestUnit = "mm" Status = 'NonProcessed' TestId = "127" / >
    < DocStsMsg test = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "0.5042" TestUnit = "mm" Status = 'NonProcessed' TestId = "128" / >
    < DocStsMsg test = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "0.5058" TestUnit = "mm" Status = 'NonProcessed' TestId = "129" / >
    < DocStsMsg test = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "0.4967" TestUnit = "mm" Status = 'NonProcessed' TestId = "130" / >
    < DocStsMsg test = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "0.5049" TestUnit = "mm" Status = 'NonProcessed' TestId = "131" / >
    < DocStsMsg test = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "0.4972" TestUnit = "mm" Status = 'NonProcessed' TestId = "132" / >
    < DocStsMsg test = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "0.4960" TestUnit = "mm" Status = 'NonProcessed' TestId = "133" / >
    < DocStsMsg test = '0' EquipmentCode = "CHIGMA1" TesterLogin = "dpkrueger" Value = "0.4996" TestUnit = "mm" Status = 'NonProcessed' TestId = "134" / >
    < / reel >

    Can you please guide me how to do it in a single query?

    Thanks in advance.

    Function EXTRACT will force a print in your version:

    SELECT XMLElement("Coil",
             XMLAttributes(
               'http://www.w3.org/2001/XMLSchema-instance' as "xmlns:xsi"
             , 'www.tempel.com/COIL.xsd' as "xsi:noNamespaceSchemaLocation"
             )
           , XMLForest(
               COIL_ID                as "CoilId"
             , COIL_NUMBER            as "CoilNo"
             , COIL_PO_OPERATING_UNIT as "CoilPOOperatingUnit"
             , COIL_PO_NUMBER         as "CoilPONo"
             , MILL_NUMBER            as "MillNo"
             , MILL_COIL_STATUS       as "MillCoilStatus"
             , ITEM_NUMBER            as "ItemNo"
             , COIL_WEIGHT            as "Weight"
             , WEIGHT_UOM             as "UOM"
             , DOCUMENT_NUMBER        as "DocumentNo"
             , DOCUMENT_DATE          as "DocumentDate"
             , DOCUMENT_STATUS        as "DocumentStatus"
             , DOCUMENT_TYPE          as "DocumentType"
             , DOCUMENT_SOURCE        as "DocumentSource"
             )
           , XMLAgg(
               XMLElement("Tests",
                 XMLAttributes(
                   DOC_STS_MSG    as "DocStsMsg"
                 , EQUIPMENT_CODE as "EquipmentCode"
                 , TESTER_LOGIN   as "TesterLogin"
                 , VALUE          as "Value"
                 , TEST_UOM       as "TestUnit"
                 , TEST_STATUS    as "Status"
                 , TEST_ID        as "TestId"
                 )
               )
             )
           ).extract('/*')
    FROM coil
    GROUP BY COIL_ID
           , COIL_NUMBER
           , COIL_PO_OPERATING_UNIT
           , COIL_PO_NUMBER
           , MILL_NUMBER
           , MILL_COIL_STATUS
           , ITEM_NUMBER
           , COIL_WEIGHT
           , WEIGHT_UOM
           , DOCUMENT_NUMBER
           , DOCUMENT_DATE
           , DOCUMENT_STATUS
           , DOCUMENT_TYPE
           , DOCUMENT_SOURCE ;
    

Maybe you are looking for