Generate XML from Oracle Table Data

Hi All,
I am new to this network. I am also new to oracle XML package. I want a help for the below query.
CREATE TABLE EMP(ID NUMBER PRIMARY KEY, NAME VARCHAR2(10), PHONE NUMBER);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (11,'Joy',1234);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (22,'Mike',5678);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (33,'Jason',NULL);
COMMIT;
I want to export the EMP table data in a XML file with the below format.
Required Output:
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>11</ID><NAME>Joy</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>22</ID><NAME>Mike</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>33</ID><NAME>Jason</NAME></EMP></STATICDATA>
I have used some XML functions and have written the below query.
select XMLROOT(XMLELEMENT(staticdata,XMLELEMENT(EMP,XMLELEMENT(ID,ID),XMLELEMENT(NAME,NAME))), version '1.0" encoding="UTF-8') xml FROM EMP;
output of my query:
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>11</ID>
<NAME>Joy</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>22</ID>
<NAME>Mike</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>33</ID>
<NAME>Jason</NAME>
</EMP>
</STATICDATA>
But i want the out as the required output above. every record in a single line. can any one help me in achieving the required output. also can i export all the columns of the table by some thing like select * from the table in XML file ?
Thanks,
Sartaj

user13683418 wrote:
Hi All,
I am new to this network. I am also new to oracle XML package. I want a help for the below query.
CREATE TABLE EMP(ID NUMBER PRIMARY KEY, NAME VARCHAR2(10), PHONE NUMBER);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (11,'Joy',1234);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (22,'Mike',5678);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (33,'Jason',NULL);
COMMIT;
I want to export the EMP table data in a XML file with the below format.
Required Output:
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>11</ID><NAME>Joy</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>22</ID><NAME>Mike</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>33</ID><NAME>Jason</NAME></EMP></STATICDATA>
I have used some XML functions and have written the below query.
select XMLROOT(XMLELEMENT(staticdata,XMLELEMENT(EMP,XMLELEMENT(ID,ID),XMLELEMENT(NAME,NAME))), version '1.0" encoding="UTF-8') xml FROM EMP;
output of my query:
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>11</ID>
<NAME>Joy</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>22</ID>
<NAME>Mike</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>33</ID>
<NAME>Jason</NAME>
</EMP>
</STATICDATA>
But i want the out as the required output above. every record in a single line.Why?
Some things output XML all as one stream, some things naturally display it structured. It doesn't matter as the XML is still the same because by it's very nature it is a structured data definition. Anything that reads XML will be able to read it whether it's on one line (streamed) or structured.
also can i export all the columns of the table by some thing like select * from the table in XML file ?A couple of ways of exporting XML to a file...
-- DBMS_XSLPROCESSOR.clob2file
-- outputs a clob to a file
DECLARE
   ctx   DBMS_XMLGEN.ctxtype;
BEGIN
   ctx := DBMS_XMLGEN.newcontext ('select * from emp');
   DBMS_XSLPROCESSOR.clob2file (DBMS_XMLGEN.getxml (ctx), 'TEMP', 'emp.xml');
   DBMS_XMLGEN.closecontext (ctx);
END;
PL/SQL procedure successfully completed.or
..snip..
  v_xml                 XMLTYPE;
  v_doc                 XMLDOM.DOMDocument;
  v_dir                 VARCHAR2(2000);
  v_file                VARCHAR2(2000);
BEGIN
  v_xml := ... populate with XML ...;
  v_dir := 'TEST_DIR'; -- directory object name (in UPPER CASE)
  v_file := 'myfile.xml';
  v_doc := DBMS_XMLDOM.NEWDOMDOCUMENT(v_xml);
  DBMS_XMLDOM.WRITETOFILE(v_doc, v_dir||'\'||v_file, 'UTF-8');
  DBMS_XMLDOM.FREEDOCUMENT(v_doc);
..snip..

Similar Messages

  • Generating xml from oracle table

    Hi,
    I want to generate xml form an oracle table and using sql developer, oracle express 10g, xdk forler is also unzipped under oracle express folder, still getting following error: code used
    var g_clob clob;
    declare
         l_ctx  dbms_xmlquery.ctxHandle;
         l_clob clob;
        begin
          l_ctx := dbms_xmlquery.newContext('select * from scott.emp');
          dbms_lob.createtemporary(:g_clob,true,dbms_lob.session);
          :g_clob := dbms_xmlquery.getXml(l_ctx);
        end;
        /ORA-06550: line 2, column 14:
    PLS-00201: identifier 'DBMS_XMLQUERY.CTXHANDLE' must be declared
    Thanks in advance

    Hi,
    DBMS_XMLQUERY is a wrapper for methods from the Java class "oracle.xml.sql.query.OracleXMLStaticQuery".
    The problem is that Oracle 10g XE doesn't have a JVM, so you can't use this package.
    Use DBMS_XMLGEN instead, it provides similar functionalities and is more efficient (C-based) :
    SQL> var g_clob clob
    SQL> DECLARE
      2    l_ctx    dbms_xmlgen.ctxHandle;
      3  BEGIN
      4    l_ctx := dbms_xmlgen.newContext('select * from scott.emp');
      5    :g_clob := dbms_xmlgen.getXML(l_ctx);
      6    dbms_xmlgen.closeContext(l_ctx);
      7  END;
      8  /
    PL/SQL procedure successfully completed.
    SQL> set long 5000
    SQL> set pages 1000
    SQL> print g_clob
    G_CLOB
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
      <EMPNO>7369</EMPNO>
      <ENAME>SMITH</ENAME>
      <JOB>CLERK</JOB>
      <MGR>7902</MGR>
      <HIREDATE>17/12/80</HIREDATE>
      <SAL>800</SAL>
      <DEPTNO>20</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7499</EMPNO>
      <ENAME>ALLEN</ENAME>
      <JOB>SALESMAN</JOB>
      <MGR>7698</MGR>
      <HIREDATE>20/02/81</HIREDATE>
      <SAL>1600</SAL>
      <COMM>300</COMM>
      <DEPTNO>30</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7521</EMPNO>
      <ENAME>WARD</ENAME>
      <JOB>SALESMAN</JOB>
      <MGR>7698</MGR>
      <HIREDATE>22/02/81</HIREDATE>
      <SAL>1250</SAL>
      <COMM>500</COMM>
      <DEPTNO>30</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7566</EMPNO>
      <ENAME>JONES</ENAME>
      <JOB>MANAGER</JOB>
      <MGR>7839</MGR>
      <HIREDATE>02/04/81</HIREDATE>
      <SAL>2975</SAL>
      <DEPTNO>20</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7654</EMPNO>
      <ENAME>MARTIN</ENAME>
      <JOB>SALESMAN</JOB>
      <MGR>7698</MGR>
      <HIREDATE>28/09/81</HIREDATE>
      <SAL>1250</SAL>
      <COMM>1400</COMM>
      <DEPTNO>30</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7698</EMPNO>
      <ENAME>BLAKE</ENAME>
      <JOB>MANAGER</JOB>
      <MGR>7839</MGR>
      <HIREDATE>01/05/81</HIREDATE>
      <SAL>2850</SAL>
      <DEPTNO>30</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7782</EMPNO>
      <ENAME>CLARK</ENAME>
      <JOB>MANAGER</JOB>
      <MGR>7839</MGR>
      <HIREDATE>09/06/81</HIREDATE>
      <SAL>2450</SAL>
      <DEPTNO>10</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7839</EMPNO>
      <ENAME>KING</ENAME>
      <JOB>PRESIDENT</JOB>
      <HIREDATE>17/11/81</HIREDATE>
      <SAL>5000</SAL>
      <DEPTNO>10</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7844</EMPNO>
      <ENAME>TURNER</ENAME>
      <JOB>SALESMAN</JOB>
      <MGR>7698</MGR>
      <HIREDATE>08/09/81</HIREDATE>
      <SAL>1500</SAL>
      <COMM>0</COMM>
      <DEPTNO>30</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7900</EMPNO>
      <ENAME>JAMES</ENAME>
      <JOB>CLERK</JOB>
      <MGR>7698</MGR>
      <HIREDATE>03/12/81</HIREDATE>
      <SAL>950</SAL>
      <DEPTNO>30</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7902</EMPNO>
      <ENAME>FORD</ENAME>
      <JOB>ANALYST</JOB>
      <MGR>7566</MGR>
      <HIREDATE>03/12/81</HIREDATE>
      <SAL>3000</SAL>
      <DEPTNO>20</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7934</EMPNO>
      <ENAME>MILLER</ENAME>
      <JOB>CLERK</JOB>
      <MGR>7782</MGR>
      <HIREDATE>23/01/82</HIREDATE>
      <SAL>1300</SAL>
      <DEPTNO>10</DEPTNO>
    </ROW>
    </ROWSET>Or, using SQL/XML functions :
    SELECT XMLElement("ROWSET",
             XMLAgg(
               XMLElement("ROW",
                 XMLForest(empno, ename, job, mgr, hiredate, sal, comm, deptno)
           ).getClobVal()
    FROM scott.emp
    ;

  • How to add doctype when generating XML from an arbitrary data structure

    I was reading SUN's tutorial "Working with XML - PART IV: Using XSLT". Inside this tutorial, in 3, it talks about how to generate XML from an arbitrary data structure making use of a XMLReader and a Transformer. The example only shows adding elements. Is there a way to add DTD information in the XML generated, i.e. <!DOCTYPE ... >? What APIs can I use?
    Thanks,
    Alex

    The simplest way seems to me is to use a XSL file for that. The <xsl:output> attributes doctype-system and doctype-public generate the DTD declaration <!DOCTYPE YOUR_ROOT SYSTEM "yourDTDfile.dtd"> and <!DOCTYPE YOUR_ROOT PUBLIC "yourDTDfile.dtd">, respectively.
    When calling transformerInstance.transform() the XSLT processor performs the identity transformation - it just copies elements, attributes, content, processing instructions and comments to the result stream.
    If you're using an xsl file for your transformation already, simply add <xsl:output doctype-system="yourDTDfile.dtd"/> to your existing XSL file.
    If you're only using the identity transformation you'd need to change the line of code where you obtain the transformer instance from the TransformerFactory to:
    t_factory.newTransformer(new StreamSource("test.xsl"));
    and use this as test.xsl:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output doctype-system="yourDTDfile.dtd"/>
       <!-- this is the identity transformation -->
       <xsl:template match="*|@*|comment()|processing-instruction()|text()">
          <xsl:copy>
             <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
          </xsl:copy>
       </xsl:template>
    </xsl:stylesheet>Good luck.

  • Generating xml from diff tables in a db

    hi,
    i need to write a oracle procedure, which when called generates xml doc (building xml from different tables in database.). i got the DTDs . but i still dont understand how can the data be pulled from diff tables and put in the one xml? can anyone give me rough idea.. i know that i have to use xmlquery and xml_save packages... but still not much clear..
    i m working on oracle 8i database. any help is appreciated.. thanks.

    Any feedback to the above questions would be greatly appreciated!

  • Creating XML from Oracle Tables

    Would it be possible to post me a snapshot of the ODI Flow diagram for an Oracle to XML conversion? Does the staging area have to be on the Target (XML)? What KMs & CM should be used? Can the XML be written straight back to an .xml file? What should the XML Schema look like?
    These are the KMs I use: LKM-SQL to SQL; IKM-SQL Incremental Update; CKM-SQL.
    My flow is straight from source (oracle) to target (xml), with staging area on target (doesn't feel right).
    My Oracle Dataserver & Schema work fine. Not sure about the XML dataserver setup though - I think this is where the problem lies. These are my JDBC settings:
    - com.sunopsis.jdbc.driver.xml.SnpsXmlDriver
    - jdbc:snps:xml?f=E:\Oracle ODI\Member.xsd
    I am evaluating ODI for a client and I wanted to throw together a quick demo showing how easily ODI can generate XML from any source. I know this is the case as I understand the concept of ODI's components - just haven't had time to read manuals thoroughly.
    Many thanks for your help,
    Steve

    Hello,
    1. Try to test the connection to the XML dataserver.
    2. Create a model and reverse-engineer this dataserver. You'll see what the XML structure is mapped to immediately.
    3. Integrate data to this model (using standard KM targeting "SQL").
    You can put the staging area on the Oracle source or in the XML driver if you want. Both solutions will work.
    just haven't had time to read manuals thoroughly.I think you should quickly read the "Sunopsis ODI with... XML" section in the manual.
    It is not very long and very helpful. Have also a quick look at the XML driver documentation.
    Regards,
    -FX

  • Generating xml from oracle 10g with BLOB image

    Hello All,
    I have employee table with id(primary key), firstname,lastname
    and I have portrait table with id(secondary key from employee table),image (blob)
    portrait table store images of the employees which are in the employee table.
    I want to generate following xml output
    <rowset>
    <id> </id>
    <firstname> </firstname>
    <lastname> </lastname>
    <portrait>base64formatted string containing image of the employee for the particular id specified in the id tag</portrait>
    </rowset>
    and save this xml as id.xml into a particular folder in the c drive and generate such xmls for each and every row of the emplyee table...
    e.g. if i have 200 emplyees with id as 1 ,2 ,.....,200 and their respective portraits into portrait table; then I want to save these as separate xml files with the names 1.xml , 2.xml , .....200.xml inside a folder say : C:\temp...
    Any help is highly appreciated
    Edited by: user1030398 on Sep 28, 2010 12:01 PM
    Edited by: user1030398 on Sep 28, 2010 12:02 PM

    I was going to write up a longer answer, but then I realized this post contains pretty much all you need
    http://www.liberidu.com/blog/?p=365
    I like using XMLElement/XMLForest to build the XML as it gives you the most control.
    In the first example on Marco's website, you would just use dbms_xslprocessor.clob2file to write each file out to disk with a CURSOR FOR loop instead of doing a single OPEN/FETCH/CLOSE. The cursor would return two columns, employee.id and the generated XML. The filename would be based on the "id" column returned by the CURSOR.
    Assumption: The machine that Oracle resides on has the "C:\temp" directory that you want to write to. You cannot use this method to right files onto a client machine.
    Hope that gets you started.

  • Generating XML from Oracle DB

    While generating XML data from Oracle relational database, using the following SQL statement,
    SELECT XMLElement("Date", VioDate)
    FROM TableName
    WHERE VioId= 10;
    I am getting the result as :
    [][][][]<Date>2010-03-22</Date>
    There four small squares coming before the xml element.
    Can anyone let me know why I am getting this and how to correct it.
    I am using Oracle SQL Developer version 1.2.1 Build MAIN - 32.13 to run the above statement.
    Regards

    Hi,
    Probably an issue about how the client "implicitly" converts an XMLType to display its lob content.
    You may use getStringVal() or getClobVal() methods to get the content :
    SQL*Plus: Release 10.1.0.4.2 - Production on Lun. Mars 29 16:28:39 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connecté à :
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select xmlelement("TEST", 'ABC') from dual;
    XMLELEMENT("TEST",'ABC')
    SQL> select xmlelement("TEST", 'ABC').getclobval() from dual;
    XMLELEMENT("TEST",'ABC').GETCLOBVAL()
    <TEST>ABC</TEST>HTH

  • Create flat file from oracle table data

    d_adp_num char(10)
    d_schd_date char(8)
    d_sched_code char(25)
    d_pay_code char(50)
    d_mil_start char(4)
    d_mil_end char(4)
    d_duration char(5)
    d_site_code char(4)
    d_dept_id char(6)
    select payroll_id,
    schedule_date,
    reason_code ,(sched_code)
    reason_code, (pay_code)
    start_time,
    end_time,
    total_hours,
    site_code,
    department_id
    from dept_staff
    where schedule_date between (sysdate+1) and (sysdate+90)
    loading some data instead for the date range.
    sched_code - 'Unavailable' if reason_code = 'OD' and 'LA'
    pay_code - 'BD Berevevement' if reason_code = 'BD'
    'UP Unexcused PTO' if reason_code = 'UP'
    'RG' if reason_code = 'SH'
    'PTO' if reason_code = 'VA'
    these are a few.....
    start_time and end_time - convert into military time
    based on start_ampm and end_ampm
    Based on this, I need help to create a flat file. Attaching sample of flat file and data from dept_staff
    If site_code is there then no need to get department_id( see sample flat file)
    sample data for flat file
    ZZW002324006072012 PTO
    0800160008.00
    ZZW002428106072012 RG
    1015174507.50HM34
    ZZW002391606072012 RG
    1100193008.50
    ZZW002430406072012 RG
    1100193008.50 130000
    dept_staff table data
    PAYROLL_ID     SCHEDULE_DATE     REASON_CODE     REASON_CODE_1     START_TIME     START_AMPM     END_TIME     END_AMPM     TOTAL_HOURS     SITE_CODE     DEPARTMENT_ID
    ZZW0024468     6/8/2012     SH     SH     730     A     400     P     850          12
    ZZW0000199     6/8/2012     SH     SH     730     A     400     P     850          14
    ZZW0023551     6/8/2012     SH     SH     1145     A     930     P     975     GH08     95
    ZZW0024460     6/8/2012     SH     SH     515     A     330     P     1025     GH08     95
    ZZW0023787     6/8/2012     SH     SH     630     A     300     P     850          24
    ZZW0024595     6/8/2012     TR     TR     730     A     400     P     850          90
    ZZW0023516     6/8/2012     OD     OD     800     A     400     P     800          95
    ZZW0023784     6/8/2012     OD     OD     800     A     400     P     800          5
    ZZW0024445     6/8/2012     SH     SH     1145     A     930     P     975     GH08     5
    ZZW0024525     6/8/2012     OD     OD     800     A     400     P     800          23
    ZZW0024592     6/8/2012     TR     TR     730     A     400     P     850          5
    ZZW0024509     6/8/2012     SH     SH     830     A     330     P     700     MK21     95
    ZZW0023916     6/14/2012     SH     SH     1100     A     730     P     850          27

    user_anumoses wrote:
    Any examples, please provide? Thankshttp://www.lmgtfy.com/?q=oracle+utl_file+example
    Handle:     user_anumoses
    Status Level:     Newbie
    Registered:     Jun 9, 2009
    Total Posts:     155
    Total Questions:     60 (55 unresolved)
    why so MANY unanswered questions?

  • Generate xml from a table and insert the xml into another table

    I want to generate an xml file from a table and insert it into another table all in one tsql
    insert into table B(xmlfile)
    select * from tableA
    FOR
    XML
    PATH('ac'),TYPE,ELEMENTS
    XSINIL,ROOT('Accum')
    Is not working any help

    I have solved my issue all I did was to change my column datatype to xml

  • Generating xml from oracle-data

    In our company we have to export customer-data to xml using a predefined format (which we cannot change).
    This xml will subsequently be used to import the data into another system.
    I'm not that familiar with XML. Most of the work can be done using dbms_xmlgen which is pretty simple and straightforward to use
    There is one type of element I cannot place correctly in the specification
    The use of foreign keys. For instance
    A employee has a foreign key to a bussiness unit that should be written down in the xml
    when using "normal" dbms_xmlgen the tag would be like
    <bussinessunit>"bisut100"</bussinessunit>
    But the specification specifies the following format
    <bussinessunit bussinesunitId="bisut100"/>
    Any idea how to get this using dbms_xmlgen?
    Or if not possible with dbms_xmlgen how could this easily be achieved?

    Thanks for the reply and the challenge is more to generate the closing tag exactly like in the specification
    The following is a snippet of what is required
    -<employee>
    <id>2</id>
    <empno>102105<empno>
    -<name>
    <firstname>Tom</firstname>
    <lastname>Hanks</lastname>
    </name>
    <bussinessunit bussinesunitId="bisut100"/>
    <employee>
    -<employee>
    <id>3</id>
    I wonder how to achieve the line
    <bussinessunit bussinesunitId="bisut100"/>
    I tried using
    DBMS_XMLGEN.setNullHandling(qryCtx, DBMS_XMLGEN.EMPTY_TAG);
    and then the construction
    qryCtx := DBMS_XMLGEN.newContext(
    ' select id, custom0 bussinessunit , company_id "@bussinessunitId", lname
    from tpt_employees t
    where rownum < 2
    and custom0 is null');
    Unfortunately, the resulting xml-line
    <BUSSINESSUNIT bussinessunitId = "1" <BUSSINESSUNIT/>
    is not the xml I had hoped for (it's not valid as well)

  • Generating XML File with Table data...

    Hi All,
    Bear with me, with my Oracle XML knowledge,,,
    we have Oracle 8i ( Relaease 3) as our database, and managegement want to have XML type of Text file, with respect to data in the Customer Table. Expected XML tags would be the Column Names of the Table.
    Table has three columns,, Name, Address, Telephone.
    So desired XML file looks like below:
    <Name>John Hunter</Name><Address> City Road, London</Address><Telephone>1223223</Telephone>
    If I deceided to do this task using PL/SQL, how could I start it,,,, All comments are welcome, this is the first time that I am going to generate this type of file ,,,

    Hi Chandana,
    You can check out the DBMS_XMLQUERY package for this purpose. It provides XMLType functionality in Oracle 8i. You can access the documentation for the same at:
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/d_xmlque.htm#ARPLS066
    If you happen to have access to Oracle 9i, then you can use XMLType Views provided with XML DB for your requirement.
    Thanks
    Shefali

  • Generate XML from a table

    Hi all,
    I have to generate an xml as given in the below format:
    There are 5 subjects.
    Rules to frame the xml:
    1) Whether students have opted for each subjects empty tags should be present , for eg: subCodeOne
    2) If there are duplicates in studid it has to be removed for each subject code.
    3) <subCodeOneStud> -- student details about subject code 1
    <studId> --- students name without duplicates
    <subCodeOnemarks> --- student marks for subject code1
    <subCodeOnePass> -- If atleast one student has passed in that subject this has to be set to Y
    In case of scenarios like 1 it should be N
    FORMAT:
    =======
            <subCodeOneStud>
              <StudId></StudId>
         </subCodeOneStud>
         <subCodeOnemarks>
              <marks></marks>
         </subCodeOnemarks>
         <subCodeOnePass>N</subCodeOnePass>
         <subCodeTwoStud>
              <StudId>531</StudId>
         </subCodeTwoStud>
         <subCodeTwomarks>
              <marks>9414</marks>
         </subCodeTwomarks>
         <subCodeTwoPass>N</subCodeTwoPass>
         <subCodeThreeStud>
              <StudId>531</StudId>
         </subCodeThreeStud>
         <subCodeThreemarks>
              <marks>8450</marks>
              <marks>0634</marks>
         </subCodeThreemarks>
         <subCodeThreePass>N</subCodeThreePass>
         <subCodeFourStud>
              <StudId>1757</StudId>
         </subCodeFourStud>
         <subCodeFourmarks>
              <marks>0405</marks>
         </subCodeFourmarks>
         <subCodeFourPass>N</subCodeFourPass>
         <subCodeFiveStud>
              <StudId>1757</StudId>
         </subCodeFiveStud>
         <subCodeFivemarks>
              <marks>0412</marks>
         </subCodeFivemarks>
         <subCodeFivePass>N</subCodeFivePass>
    SELECT
    sub_i,/*to remove duplicate studnames */
    extract(
    deleteXML(
    xmlelement("root", xmlparse(content stud_ids))
    , '/root/studId[preceding-sibling::studId=.]'
    , '/root/studId'
    ) students,
    marks,
    pass_flag,
    ,sub_i_w
    FROM
    SELECT
    sub_i,sub_i_w,
    '<studId>'||LTRIM(MAX(sys_connect_by_path(stud_name,'</studId><studId>')),'</studId><studId>')||'</studId>' stud_ids,
    '<marks>'||LTRIM(MAX(sys_connect_by_path(marks,'</marks><marks>')),'</marks><marks>')||'</marks>' marks,
    DECODE(MAX(pass_f),1,'Y','N') pass_flag
    FROM
    (SELECT
    sub_i,sub_i_w,
    stud_name,
    marks,
    pass_f,
    ROW_NUMBER() OVER(PARTITION BY PSN_ID ORDER BY sub_i ) RN
    FROM
    SELECT
    LEVEL sub_i,
    REPLACE(REPLACE(INITCAP(to_char(to_date(LEVEL,'J'), 'JSP')),' ',''),'-','')  sub_i_w /*subject id in words for the outer most tag */
    FROM
    DUAL
    CONNECT
    LEVEL <= 5
    )A
    LEFT OUTER JOIN
    (SELECT sub_i,
    stud_name,
    marks,
    decode(result,'Y',1,0) pass_f,
    FROM
    marklist
    )B
    ON (A.sub_i=B.sub_i)
    START WITH RN = 1
    CONNECT BY PRIOR RN = RN - 1 AND PRIOR sub_i = sub_i
    GROUP BY sub_i,sub_i_w
    )Doubts:
    ========     
    1) I am using the above query to generate studId and marks tag for all the five subjects
    I am getting an error: "ORA-01854:julian date must be between 1 and 5373484"
    Can any one help me in resolving this?
    2) To get the final xml i may have to add the below select query to the above query. But this kind of concatenation to get the tag , throws an error: right parenthesis
    SELECT
    REPLACE(
    REPLACE(
    XMLAGG(
    XMLELEMENT("subCode"||sub_i||"Stud",students),
    XMLELEMENT("subCode"||sub_i||"marks",marks),
    )).getStringVal(),'&&lt;','<'),'&&gt;','>')
    FROM3) Is this way of writing a query to generate the xml is effiecient .I am using oracle 10g
    Thanks in advance
    Edited by: BluShadow on 17-Oct-2011 08:09
    added {noformat}{noformat} tags for formatting.  Please read {message:id=9360002} and learn to do this yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Java application expects the tags to be like this :(I see...
    Don't forget to format what you post here as BluShadow kindly did for you earlier.
    Apart from the obvious readability reasons, that's particularly important for XML or HTML code because the forum software here might interpret some tags and not render them correctly.
    Thanks for the sample data anyway.
    This should get you going :
    with subjects as (
      select level as sub_id
           , initcap(to_char(to_date(level,'J'), 'JSP')) as sub_id_sp
      from dual
      connect by level <= 5
    select xmlagg(
             xmlconcat(
               xmlelement(evalname('subCode'||sub_id_sp||'Stud'),
                 xmlagg( case when rn = 1 then xmlelement("StudId", stud_name) end )
             , xmlelement(evalname('subCode'||sub_id_sp||'marks'),
                 xmlagg( xmlelement("marks", marks) )
             , xmlelement(evalname('subCode'||sub_id_sp||'Pass'),
                 nvl(max(case when pass_f = 'Y' then pass_f end), 'N')
           ).extract('/*') -- to "pretty-print" the result (not mandatory)
           as result
    from (
      select s.sub_id
           , s.sub_id_sp
           , m.stud_name
           , m.marks
           , m.pass_f
           , row_number() over(partition by s.sub_id, m.stud_name order by null) rn
      from subjects s
           left outer join marklist m on m.sub_id = s.sub_id
    group by sub_id, sub_id_sp
    RESULT
    <subCodeOneStud>
      <StudId/>
    </subCodeOneStud>
    <subCodeOnemarks>
      <marks/>
    </subCodeOnemarks>
    <subCodeOnePass>N</subCodeOnePass>
    <subCodeTwoStud>
      <StudId>raj</StudId>
      <StudId>rosy</StudId>
    </subCodeTwoStud>
    <subCodeTwomarks>
      <marks>20</marks>
      <marks>80</marks>
    </subCodeTwomarks>
    <subCodeTwoPass>Y</subCodeTwoPass>
    <subCodeThreeStud>
      <StudId/>
    </subCodeThreeStud>
    <subCodeThreemarks>
      <marks/>
    </subCodeThreemarks>
    <subCodeThreePass>N</subCodeThreePass>
    <subCodeFourStud>
      <StudId>jaya</StudId>
      <StudId>padma</StudId>
      <StudId>rosy</StudId>
    </subCodeFourStud>
    <subCodeFourmarks>
      <marks>100</marks>
      <marks>40</marks>
      <marks>30</marks>
      <marks>80</marks>
    </subCodeFourmarks>
    <subCodeFourPass>Y</subCodeFourPass>
    <subCodeFiveStud>
      <StudId>jai</StudId>
      <StudId>padma</StudId>
    </subCodeFiveStud>
    <subCodeFivemarks>
      <marks>100</marks>
      <marks>90</marks>
    </subCodeFivemarks>
    <subCodeFivePass>Y</subCodeFivePass>

  • Create XML from oracle table if not null

    Hello dear community,
    I have a problem by creating an XML file in oracle and hope you could help me.
    What I have is an table named "description" with three rows there:
    person varchar2(50)
    adress varchar2(50)
    Nr number
    Reading this table I am going to create an XML file like that:
    Procedure Create_XML (iNr IN number, cXmlFile OUT clob) is
    varPerson varchar2(50);
    varAdress varchar2(50);
    Begin
    varPerson := ... ;
    varAdress := ... ;
    select
    xmlserialize
    content
    xmlelement
    "Head",
    xmlelement
    "Node",
    xmlelement
    "Line",
    xmlelement("ATNAM", 'PERSON'),
    xmlelement("ATWRT", PERSON),
    xmlelement("ATFOR", varPerson)
    xmlelement
    "Line",
    xmlelement("ATNAM", 'ADRESS'),
    xmlelement("ATWRT", ADRESS),
    xmlelement("ATFOR", varAdress)
    indent
    ) as xml
    into cXmlFile
    from description
    where Nr = iNr;
    End Create_XML;
    What I want to do, is just to take the value from the both rows "person" and "adress" and fill the xml file with additional info.
    1. My first question is, if it is possible to create any kind of routine for the xmlelement "Line" instead of doing it all over and over again? How?
    2. An other issue is very important to me: how can I check here if f.i. the row person is empty or not? If it is, the xmlelement "Line" with person information in it should not be created at all.
    Any answer would really help me!
    Thank you a lot in advance!

    Hi,
    Could you elaborate a little on your first question?
    Are you looking for something like :
    SELECT xmlquery(
    '<head>
      <node>
       for $i in ora:view("DESCRIPTION")/ROW[NR=$nr]/*[local-name()!="NR"]
       return element Line {
        element ATNAM {local-name($i)},
        element ATWRT {$i/text()}
      </node>
    </head>'
    passing sys_xmlgen(1) as "nr"
    returning content
    FROM dual;but since you use a specific variable for each "line" type, I don't see how we can generalize the construction of the line element.

  • Generating XML from relational tables and storing back in CLOB field

    I have been reviewing the documentation and trying to figure out the best approach. I am on v 10.2.0.3 and need to select from a parent table and three child tables and want to generate the results as xml that I will place in a clob field in another table. I looked at XMLQuery and dbms_xmlgen.getxml. The difference appears to be that getxml allows you to code traditional sql to join the tables.
    I would greatly appreciate it if someone could provide some feedback and any sample code along the line that I describe above.
    Thank you in advance for your help!
    Jerry

    Any feedback to the above questions would be greatly appreciated!

  • Using FDM to load data from oracle table (Integration Import Script)

    Hi,
    I am using Integration Import Script to load data from oracle table to worktables in FDM.
    i am getting following error while running the script.
    Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done
    Attaching the full error report
    ERROR:
    Code............................................. -2147217887
    Description...................................... Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
    At line: 22
    Procedure........................................ clsImpProcessMgr.fLoadAndProcessFile
    Component........................................ upsWObjectsDM
    Version.......................................... 1112
    Thread........................................... 6260
    IDENTIFICATION:
    User............................................. ******
    Computer Name.................................... *******
    App Name......................................... FDMAPP
    Client App....................................... WebClient
    CONNECTION:
    Provider......................................... ORAOLEDB.ORACLE
    Data Server......................................
    Database Name.................................... DBNAME
    Trusted Connect.................................. False
    Connect Status.. Connection Open
    GLOBALS:
    Location......................................... SCRTEST
    Location ID...................................... 750
    Location Seg..................................... 4
    Category......................................... FDM ACTUAL
    Category ID...................................... 13
    Period........................................... Jun - 2011
    Period ID........................................ 6/30/2011
    POV Local........................................ True
    Language......................................... 1033
    User Level....................................... 1
    All Partitions................................... True
    Is Auditor....................................... False
    I am using the following script
    Function ImpScrTest(strLoc, lngCatKey, dblPerKey, strWorkTableName)
    'Oracle Hyperion FDM Integration Import Script:
    'Created By:     Dhananjay
    'Date Created:     1/17/2012 10:29:53 AM
    'Purpose:A test script to import data from Oracle EBS tables
    Dim cnSS 'ADODB.Connection
    Dim strSQL 'SQL string
    Dim rs 'Recordset
    Dim rsAppend 'tTB table append rs object
    'Initialize objects
    Set cnSS = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    Set rsAppend = DW.DataAccess.farsTable(strWorkTableName)
    'Connect to SQL Server database
    cnss.open "Provider=OraOLEDB.Oracle.1;Data Source= +server+;Initial Catalog= +catalog+;User ID= +uid+;Password= +pass+"
    'Create query string
    strSQL = "Select AMOUNT,DESCRIPTION,ACCOUNT,ENTITY FROM +catalog+.TEST_TMP"
    'Get data
    rs.Open strSQL, cnSS
    'Check for data
    If rs.bof And rs.eof Then
    RES.PlngActionType = 2
    RES.PstrActionValue = "No Records to load!"
    Exit Function
    End If
    'Loop through records and append to tTB table in location’s DB
    If Not rs.bof And Not rs.eof Then
    Do While Not rs.eof
    rsAppend.AddNew
    rsAppend.Fields("PartitionKey") = RES.PlngLocKey
    rsAppend.Fields("CatKey") = RES.PlngCatKey
    rsAppend.Fields("PeriodKey") = RES.PdtePerKey
    rsAppend.Fields("DataView") = "YTD"
    rsAppend.Fields("CalcAcctType") = 9
    rsAppend.Fields("Amount") = rs.fields("Amount").Value
    rsAppend.Fields("Desc1") = rs.fields("Description").Value
    rsAppend.Fields("Account") = rs.fields("Account").Value
    rsAppend.Fields("Entity") = rs.fields("Entity").Value
    rsAppend.Update
    rs.movenext
    Loop
    End If
    'Records loaded
    RES.PlngActionType = 6
    RES.PstrActionValue = "Import successful!"
    'Assign Return value
    SQLIntegration = True
    End Function
    Please help me on this
    Thanks,
    Dhananjay
    Edited by: DBS on Feb 9, 2012 10:21 PM

    Hi,
    I found the problem.It was because of the connection string.The format was different for oracle tables.
    PFB the format
    *cnss.open"Provider=OraOLEDB.Oracle.1;Data Source= servername:port/SID;Database= DB;User Id=aaaa;Password=aaaa;"*
    And thanks *SH* for quick response.
    So closing the thread......
    Thanks,
    Dhananjay

Maybe you are looking for

  • MP3 on desktop wont open in iTunes or add to library, has done so in past

    I've been trying to add two MP3 files that are on my desktop with no luck. If I double click on them, iTunes opens but does not play the music, and the music is not in my library. I've tried adding them to the music folder or selecting "Add to librar

  • Invert text to white on black

    I find reading white tex on black background than white on black. EG on Samsung. Apple can invert the colours. Surely Sony can. just moved from and old Samsung. Just assumed on android it would be easy.

  • XI in an insurance company

    Hi, If XI is being implemented in an insurance company. Could any one guide me with the correct implementation steps, in the context of an insurance company. Thanks, -Naveen.

  • Music store error message- please help!

    I've read previous posts regarding this error- just want to make sure I have the same problem before I uninstall the software. I am able to access the music store, but as soon as I hit the search or power search mode, I receive the error message " It

  • Ext for: Dynamic Dropdownlist Search Page

    Hi there, DW CS3, PHP MySQL DB on Win XP Prof. On one of my web sites, I have a recordset. I want do do a search over 3 or 4 drop down lists. The values in drop down list number 2 must be the result of the choice in drop down 1; 3 must be the result