dbms_xmlgen-> create oracle XML attribute with value type

I use the dbms_xmlgen to create my xml message and I use the oracle TYPEs to create xml message elements.

I need to create something like this:
< type Emp 'name' = > xyz < / Emp >

I tried to create the type as below
create type emp_t as an object ("type" "@type")...

But do not know how I need to set the value of this attribute.

Help, please. Thanks in advance for your help.

Can be

SQL> select * from v$version where rownum=1;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

SQL>
SQL> select  dbms_xmlgen.getxml('select ename, ''name'' as "@type" from emp') from dual;

DBMS_XMLGEN.GETXML('SELECTENAM
--------------------------------------------------------------------------------


 
  SMITH
 
 
  ALLEN
 
 
  WARD
 
 

SQL> 

Tags: Oracle Development

Similar Questions

  • Create the virtual machine with the type of controller SCSI LSI logic SAS with PowerCLi

    Hey guys,.

    IM the difficulty to create a virtual machine with the type of controller SCSI to "LSI Logic SAS". The cmdlet New - VM im struggling to find where to create the type of controller?

    If you create a virtual machine without specifying a disk it will create a 4 GB SCSI type thick (0:0) hard drive 1 with 0 Parrall default BusLogic SCSI controller.

    What im wanting to do is to create a disk hard which is thin Prov. and create SCSI LSI logic SAS controller is set to.

    New-VM -name VMSTORE23 -$vmhost $esxhost MemoryMB- 4096 NumCpu- 2 -NetworkName "Vlan 6 Machine Virtual Network" | Get-NetworkAdapter | Set-NetworkAdapter -Type Vmxnet3 -MacAddress '00:50:56:00:00:21' -confirm:$false

    I have recived of aid by some LucD who helped direct the value of the network card in the New - VM cmdlet as follows. But I'm not able to add a hose for hard disk also like:

    | Get-hard drive | Together-hard drive - Datastore $datastore - slim StorageFormat

    And I have no idea how change the type of SCSI conroller or create it with the correct configuration?

    Any help would be great,

    Thanks in advance

    Eddie

    Greetings, steddyeddie-

    You should be able to use Set - hard drive and SCSI controller Set cmdlets to set the storage format of your hard drive and the SCSI controller type, respectively.  You were close to on the part of game - hard drive .  Try something like:

    ## get the VM object $vmVMSTORE23 = Get-VM VMSTORE23 ## set the harddisk storageformat to thin$vmVMSTORE23 | Get-HardDisk | Set-HardDisk -StorageFormat Thin ## set the SCSI controller type$vmVMSTORE23 | Get-ScsiController | Set-ScsiController -Type VirtualLsiLogicSAS
    

    It could pack in to your existing order to keep it as a good word, but for readability.

    Enjoy

  • How to change the name of the attribute with ALTER TYPE?

    I have a question. How can I change the name of the attribute with ALTER TYPE? example:

    CHANGE the type of ATTRIBUTE to CHANGE type_attribute...

    What should I put in «...» "to change the attribute name?

    Thank you...

    What should I put in «...» "to change the attribute name?

    You can not. You can change the data type.

    You can delete and recreate the attribute:

    ALTER TYPE type DROP ATTRIBUTE type_attribute;
    ALTER TYPE type ADD ATTRIBUTE new_type_attribute data_type;
    

    Max

  • create multiple xml attributes

    Hi all

    I'm not very experienced with the LabVIEW XML functions... so far I find that they are a major pain in the banana, in fact.  I got as far as being able to analyze an existing xml file, but now I need to write a.

    The file I'm writing is quite simple: one tag with several attributes.  Because multiple data sources will create these files, I do not have the option of joyfully using the schema of LabVIEW and trust that everything will be fine.  In addition, these features give enough visibility on what is written where and how and I'm nervous about 'black boxes' - I would like to know exactly what is happening and where, when I write code.  Therefore, I must use XML to create this file instead.

    A search revealed the Forum code to create a unique attribute.  When I try to adapt this code to create several attributes, I get error-2602: node inserted in the wrong place.

    Can someone please look at this example and tell me where I blew it away?  I'm sure it's something stupid, but I can't.

    Thank you all!

    Diane

    You were very close.  Just move the append method of the child outside the loop and you're all good. The child is the element, in order to generate (name, value, attributes), then add it.

  • Enforcement of XML attribute with a structure?

    I use xmlParse() to read an XML file into a structure and then deal with the structure (replace some of the XML attributes) and then write structure back as an XML file. The problem is that I lost the original order of the XML attributes when I convert a structure and instead end up with a new attribute for each element that is alphabetical order.

    In other: c = 'text' d = 'text' element has = "text" / >

    be rewritten in the form: element = 'text' c = 'text' d = "text" / >

    which is a problem for this application.

    Is it possible to work with XML in CF but keep ordering attribute (LinkedHashMap instead of a structure, perhaps)?

    Thank you.

    Walter

    If you need to control the order of the attributes, you must write your xml code on hand, according to the XML specification, ordering attribute must not be important, so strictly speaking your condition here requires something XML which is contrary to his intention.  And, therefore, has no way of making CF respect something that inherently isn't supposed to be respected.

    NB: "I use xmlParse() to read an XML file in a structure"... xmlParse() creates an XML object, not a struct, so what you ask in your last paragraph doesn't really sense.  xmlParse() will only create an XML object. If you want to read the XML data as something else than XML, you need to write your own function.

    The best solution here, if poss, is to remove the importance of the order attribute in your application, because it is "wrong" to deduct any order, and you do a little logic a rod for your own back based on this ranking.

    Not an answer 'just do it like this', I'm sorry, but that's what you get when the question is immersed in a Pandora's box... ;-)

    --
    Adam

  • XML attribute 'with' reserved?

    While working on an implementation of XMPP I notice the "with" continuous attribute to throw errors when trying to access to set or get the data from it. What is a reserved word or something? So in fact difficult given "with" is widely used in the specifications...

    var XML = < rootNode >

    < = 'test' without the 'rest' = > cool < / item >

    < / rootNode >;

    trace (XML. Item.@without); No problem

    trace (XML. Item.@with); Uncomment and you will get the error "syntax error: expected identifier with.»

    It may be how access you during the review of the reserved words. Try trace (xml.item.attribute ('with')); or trace(xml.item.@["with"]);

  • How to create a ViewObject attribute where value to get database query

    Hi Expert,

    I have a case for the value of database query. How to create the view additional attribute object where the value get database query?

    parameter binding of attributeId object in view I can do this in ADF with JDeveloper 11.1.1.6.

    Thank you

    Kind regards

    Wade W

    My problem is solved, maybe it's a bug in the JDeveloper 11.1.1.6.0

    I've got error (oracle.jbo.expr.JIEvalException) Houston-25077: name amount not found in the given object: oracle.jbo.server.ViewRowSetImpl@8690e3.

    When I develop by tab Overview (presentation of the business components). It is so strange, because I have an another transient viewAttribute that refer to another object in view and not get an error message like this before I create viewAttribute HeaderAmount.

    Maybe its ridiculous appearance, but when I go to View (lineVO.xml) object and tab to the source xml file, I have edited here. like to write

    <>

    Name = "HeaderAmount".

    IsUpdateable = "false".

    IsSelected = "false".

    IsPersistent = "false".

    PrecisionRule = 'true '.

    Type = "Oracle.jbo.domain.Number"

    ColumnType = 'NUMBER '.

    AliasName = 'VIEW_ATTR. '

    SQLType = 'DIGITAL' >

    <>

    Value = "ActivityHeaderId" / >

    and make sure this xml file are:

    <>

    Name = "ActHeaderView1VO".

    ViewLink = 'model. ActHeaderLineLink ".

    Type = "Oracle.jbo.Row"

    Reversed = 'true '.

    IsUpdateable = "false" / >

    When I try to re-run the application model and it's work...

    Thanks for your help. really appreciate

  • Fail to create the web service with the type of data defined by the user using the jwsc Ant task!

    Hello everyone!

    I used JAXWS to create WSDL from a file of Jehovah's witnesses.

    It's my TJ:
    -----------------------------------------------------------------------------------
    package ws;

    Import javax.jws.WebService;
    Import javax.jws.WebMethod;
    ws import. MyDataType;

    *@WebService*
    * public class MyWebService {*}
    public MyWebService()
    *{*
    *}*
    *@WebMethod*
    public MyDataType MyWebMethod (MyDataType mdt)
    *{*
    * / / mdt.setS ("I got it!"); *
    return mdt;
    *}*
    *}*
    -----------------------------------------------------------------------------------


    and this is my type of data:
    -----------------------------------------------------------------------------------
    package ws;

    * public class MyDataType {*}


    String ^ s;
    public MyDataType()
    *{*

    *}*
    * public String getS() {*}
    return s;
    *}*

    * Sets public Sub (String s) {*}
    This.s = s;
    *}*
    *}*
    -----------------------------------------------------------------------------------



    and that's my Ant build.xml
    -----------------------------------------------------------------------------------
    * < by default of the project = "all" > *.
    * < property name = "weblogic.jar.classpath" value="D:/Projects/bea103/wlserver_10.3/server/lib"/ > * "
    * < taskdef name = "jwsc" classname = "weblogic.wsee.tools.anttasks.JwscTask" > *.
    * < classpath > *.
    * < path id = "weblogic.classpath" > * "
    * < pathelement path = "WEBLOGIC_HOME" / >. *
    * < fileset dir = "${weblogic.jar.classpath}" > *.
    * < include name = "weblogic.jar" / > *.
    * < / fileset > *.
    * < / path > *.
    * < / classpath > *.
    * < / taskdef > *.
    * < target name = "all" depends = "clean, build-service" / > *.
    * < name target 'clean' = > *.
    * < delete dir = "output" / > *.
    * < / target > *.
    * < name target = 'build-service' > *.
    * <!-add jwsc and related tasks here - > *.
    * < jwsc srcdir = "" destdir = "wsoutput" > * "
    * < jws file = "MyWebService.java" type = "JAXWS" / > * "
    * < / jwsc > *.
    * < / target > *.
    * <!-< target name = "deploy" > - > <! - add wldeploy task here - > <!-< / target >-> *.
    * < / project > *.
    -----------------------------------------------------------------------------------

    I have run the Ant task, but I get this error:
    -----------------------------------------------------------------------------------
    BuildFile: build.xml

    clean:

    build service:
    [jwsc] TJ: processing module /MyWebService
    [jwsc] The analysis of source files
    [jwsc] The analysis of source files
    [jwsc] 1 TJS files processing for the module /MyWebService
    * [jwsc] [JAM] WARNING: could not resolve class MyDataType *.
    [jwsc] TJ: C:\Documents and Settings\samimi\IdeaProjects\SampleWebService\src\ws\MyWebService.java valid.
    [jwsc] Treatment of the web services JAX - WS 1...
    * [jwsc] error: couldn't get TypeDeclaration for: MyDataType apt tour: 1 *...
    ...................
    BUILD FAILED
    C:\Documents and Settings\samimi\IdeaProjects\SampleWebService\src\ws\build.xml:
    19: weblogic.wsee.tools.WsBuildException: JAX - WS web services processing error
    -----------------------------------------------------------------------------------

    Please help me solve this problem.
    Thank you
    Mojir

    I tried to compile your source code and received the same exception.
    However after compiling the MyDataType.java before running the jwsc task, I was successfully able to build the service.

    Please try the ant script below and let me know the result:

    **
    *     *
    *
    *



    <>
    srcdir = "${source.dir}" "

    DESTDIR = "${Build.dir} '"
    keepGenerated = 'true '.
    classpath = "${Class.Path} '"
    Debug = 'true '.
    verbose = "false" >

         


              

    Thank you
    Sandeep

  • Insert the XML document with values of characters &lt; or &gt;

    Hello world

    Used Oracle: version 11.2.0.3.0

    I want to insert an XML document in a binary XML field. But for an element, the value includes characters such as > or <.

    Here's an example query:

    Update / * + no_xml_query_rewrite * / ms2 set mstag = XMLQuery (' copy $tmp: = .modify (for $i in $tmp/tags/fields[@id="MS"]))

    back insert nodes (< value > TEST\n & lt; Address1 & gt; < / value >) in $i) return $tmp' from mstag content back) where psid = 5900;

    But because we're using the character & in a SQL query, this request has failed. We invited to specify the 2 values.

    So, what is the way of giving the < Address1 > value to the value of the element in the example?

    Thanks in advance

    The command is not really "fail" in itself. It is just the tool that you are using recognizes '&' characters and treats the following identifiers as replacement variables.

    What tool do you use?

    For example, in SQL * Plus you can disable this behavior through the SET DEFINE OFF or SET SCAN OFF command.

  • Create oracle.jbo.Key with String

    Hello

    I use JDeveloper 12.1.3.

    Someone give me a working example of the creation of oracle.jbo. Key with the string in the constructor.

    All the tutorial I have tried do not work for me.

    THX.

    I just did a small test case using the table HR job because he has a channel a PK.

    inside the JobsViewImpl, I've implemented a method

    public String dummyTest() {}

    String strkey1 = "01234";

    String srtkey2 = "9876";

    Key = new key (new Object() {strkey1});

    Line lines [] = findByKey (key, 1);

    If (rows.length > 0) {}

    String res = (String) rows [0] .getAttribute ("JobTitle");

    return res;

    } else {}

    return "nothing found";

    }

    }

    What called wenn of the Tester application module returns

    and the data in the table

    Summary: it works for me.

    One thing I saw is that you used a constructor that is not recommended for the key as the new Key (String) is obsolete.

    Timo

  • Basic attribute default values

    When you create a structure of the event, I noticed that you can specify values by default when you use the dbms_rlmgr.add_elementary_attribute attr_defvl. I've done this and can see my default values appear in the column user_expfil_attributes default_value.

    However, I don't see anything in the way of documentation or examples on how to use default values, once they are specified. It is possible to specify an incoming event that is missing an attribute value and then have the engine, use the default value instead?

    Thank you
    Scot

    Scot,

    The values specified for the type of object are mapped to parameters in the order listed. So, it is a general practice to set the attributes with values default to the end, so that when only a partial set of attribute values are specified, there is no ambiguity. You can still use the extended syntax (methods 4 and 5) to assign values to specific attributes.

    Kind regards
    -Aravind.

  • Error while processing 'type' attribute with the value "DistributedVirtualPortgroup.

    Hello everyone. I'm back with an API error message that I can't decipher. At first I thought that I was maybe getting the wrong version of the API, but I checked vimServiceVersions.xml and it's OK (namespace urn: vim25 a version 5.5)

    I feel like I have tried everything under the Sun and I don't know what the devil is wrong. RetrieveProperties method works VirtualMachine but not DistributedVirtualPortgroup type.

    Another hypothesis is that I am just using the connection instead of LoginByTokenmethod, but I don't know who has nothing to do with it.

    Outgoing request:

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
    <RetrieveProperties xmlns="urn:vim25">
    <_this type="PropertyCollector">propertyCollector</_this>
    <specSet>
    <propSet>
    <type>DistributedVirtualPortgroup</type>
    <all>true</all>
    </propSet>
    <objectSet>
    <obj type="DistributedVirtualPortgroup">dvportgroup-72</obj>
    </objectSet>
    </specSet>
    </RetrieveProperties>
    </soap:Body>
    </soap:Envelope>
    
    
    
    

    Error response:

    The remote server returned an error: (500) Internal Server Error.
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
     xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
    <soapenv:Fault><faultcode>ServerFaultCode</faultcode><faultstring>
    Error processing attribute &quot;type&quot; with value &quot;DistributedVirtualPortgroup&quot;
    
    while parsing MoRef for ManagedObject of type vmodl.ManagedObject
    at line 1, column 369
    
    while parsing property &quot;obj&quot; of static type ManagedObject
    
    while parsing serialized DataObject of type vmodl.query.PropertyCollector.ObjectSpec
    at line 1, column 358
    
    while parsing property &quot;objectSet&quot; of static type ArrayOfObjectSpec
    
    while parsing serialized DataObject of type vmodl.query.PropertyCollector.FilterSpec
    at line 1, column 275
    
    while parsing call information for method RetrieveProperties
    at line 1, column 180
    
    while parsing SOAP body
    at line 1, column 169
    
    while parsing SOAP envelope
    at line 1, column 0
    
    while parsing HTTP request for method retrieveContents
    on object of type vmodl.query.PropertyCollector
    at line 1, column 0</faultstring><detail><InvalidRequestFault xmlns="urn:vim25" xsi:type="InvalidRequest"></InvalidRequestFault></detail></soapenv:Fault>
    </soapenv:Body>
    </soapenv:Envelope>
    
    
    

    Too bad! I have it. Is one incorrect or no header:

    SOAPAction: "urn: vim25 / 6.0.

  • How to remove the value of the XML attribute in the Indesign file with javascript

    Hi all

    How to remove the value of the XML attribute in the Indesign file.

    1.jpg

    What error is this?

    in any case try this as well (one another),

    var myDoc = app.activeDocument;
    attrDelete(myDoc);
    function attrDelete(elm)
    {
        for (var i = 0; i < elm.xmlElements.length; i++)
        {
            try{
                for(j=0; j
    

    Vandy

  • Any ideas to convert oracle XML or CLOB type collections

    Hi all

    Have actively tried to convert collections of oracle XML or CLOB objects to be stored in the table of database for logging purposes. Tried to look for clues. You can help.

    Here is the script that I created temporarily to try the code:

    DROP TABLE insert_table;

    CREATE TABLE insert_table
    (
    Serial NUMBER (9),
    first name VARCHAR2 (35),
    name VARCHAR2 (35),
    E-mail VARCHAR2 (65).
    home_phone NUMBER (10),
    work_phone NUMBER (10),
    CONSTRAINT serial_pk PRIMARY KEY (serial)
    );

    DELETE FROM temporary_table;

    INSERT INTO temporary_table VALUES (1, "Arthur", "Wright", "[email protected]", 5439021232, NULL);
    INSERT INTO temporary_table VALUES (2, 'will', "Ball", "[email protected]", 4379021000, NULL);
    INSERT INTO temporary_table VALUES (3, 'Kerwin","Mike","[email protected]", 9018236733, 6621232356);
    INSERT INTO temporary_table VALUES (4, 'Krammer', 'Cone', '[email protected]', NULL, 3238483323);

    DROP TYPE obj_detail FORCE
    /
    DROP TYPE obj_detail_list FORCE
    /

    CREATE or REPLACE TYPE obj_detail AS OBJECT
    (Serial NUMBER (9),
    full_name VARCHAR2 (70).
    Department VARCHAR2 (10),
    assessment VARCHAR2 (1))
    /

    CREATE or REPLACE TYPE obj_detail_list AS TABLE OF THE obj_detail
    /

    DECLARE
    CTX DBMS_XMLGEN.ctxHandle;
    XML CLOB.
    obj_det_list obj_detail_list: = obj_detail_list ();
    BEGIN
    SELECT obj_detail (series,
    last_name. first name,
    "Software."
    « A »)
    LOOSE COLLECTION obj_det_list
    Of insert_table;

    CTX: = DBMS_XMLGEN.newContext ("SELECT * FROM TABLE (obj_det_list)'");
    Dbms_output.put_line (ctx);

    XML: = DBMS_XMLGEN.getXML (ctx);
    Dbms_output.put_line (xml);

    DBMS_XMLGEN.closeContext (ctx);
    END;
    /

    Hello

    "" "You're almost there. '"

    The error you have is because you try to refer to a local variable (the collection) in a static SQL string.
    A solution would be to use a binding in the query variable, but only VARCHAR2 with DBMS_XMLGEN are allowed.

    However, you can bind the collection using a REF CURSOR:

    SQL> DECLARE
      2    ctx          DBMS_XMLGEN.ctxHandle;
      3    xml          CLOB;
      4    obj_det_list obj_detail_list := obj_detail_list();
      5
      6    rc           sys_refcursor;
      7
      8  BEGIN
      9
     10   SELECT obj_detail(serial,
     11                     last_name || first_name,
     12                     'Software',
     13                     'A')
     14   BULK COLLECT INTO obj_det_list
     15   FROM temp_table;
     16
     17   OPEN rc FOR SELECT * FROM TABLE(obj_det_list);
     18
     19   ctx := DBMS_XMLGEN.newContext(rc);
     20   xml := DBMS_XMLGEN.getXML (ctx);
     21   DBMS_OUTPUT.put_line (xml);
     22
     23   DBMS_XMLGEN.closeContext(ctx);
     24   CLOSE rc;
     25
     26  END;
     27  /
    
    
    
     
      1
      WrightArthur
      Software
      A
     
     
      2
      BallWill
      Software
      A
     
     
      3
      MikeKerwin
      Software
      A
     
     
      4
      ConeKrammer
      Software
      A
     
    
    
    PL/SQL procedure successfully completed
     
    

    You don't even need DBMS_XMLGEN:

    DECLARE
    
      xml          CLOB;
      obj_det_list obj_detail_list;
    
    BEGIN
    
     SELECT obj_detail(serial,
                       last_name || first_name,
                       'Software',
                       'A')
     BULK COLLECT INTO obj_det_list
     FROM temp_table;
    
     SELECT xmltype(cursor(select * from table(obj_det_list))).getClobVal()
     INTO xml
     FROM dual;
    
     DBMS_OUTPUT.put_line (xml);
    
    END;
    /
    
  • Using functions Oracle XML - sys_xmlgen and dbms_xmlgen

    I am new to Oracle 10 g and XML. I've been reading and practice with examples and understand a point of what is happening.

    Here's my problem: I have a student athlete who can have many rewards. How can I get several scholarships to work with sys_xmlgen or dbms_xmlgen? Or is this even possible?
    The data is stored in tables, XMLType.
    This problem uses several tables as a sport table, table of students and a table of prices.

    There is an example of output of a student with multiple tags within the tag of the student price:

    < student schoolSidNumber = '999-12-6745' fulltimeEnrollmentTermHere = 'S1' fulltimeEnrollmentYearHere = "2003" action = "none" firstName = "Import" lastName = 'Test' recruited 'M' = sex = 'Y' comments = date of birth "Created from the process of import." = '1971-09-12' Address1 = "123 University Drive" city = 'University City' State 'IN' = >
    < guardianName warden = "Mr. & amp; Ms. Import Test' homeFlag = 'Y' Address1 = "123 Avenue House" city = 'Brazil' state 'IN' = / >
    < year value "2008" action = 'none' = >
    < sport sportCode = "MBB" initialCounterFlag = 'Y' action = 'save' / >
    < aidLimits sportCode = "MBB" grantInAidAmt = "10000" costAttendAmt = "11000" / >
    < price action = 'save' saAidId = '0' fundCode = 'ATHLETES' sportCode = "MBB" rolloverFlag = "N" awardPeriod = "FY" awardAmount = "5000" awardDate = "2005-08-13" / >
    < price action = 'save' saAidId = '0' fundCode = "INST" sportCode = "MBB" rolloverFlag = "N" awardPeriod = "FY" awardAmount = "2000" awardDate = "2005-08-13" / >
    < continuingEligibility classDescription = "FRESHMAN" degreeDeclareDate = "" academicIneligible = "N" degreeReqHours = '120' degreeId = '1' saCumulativeGpa = "3,397" "
    totalDegreeHours = "26" / >
    < term action = 'save' termCode = 'S1' hoursAttempted = '12' hoursEarned = '12' gpa = "4.0" fullTimeFlag = "Y" / >
    < term action = 'save' termCode = 'S2' hoursAttempted = hoursEarned "14" = "14" gpa = '3.0' fullTimeFlag = 'Y' / >
    < / year >
    < original acceptedDate = "2002-04-01" >
    < testScore p1Score = '400' p2Score = '400' testCode = "S" testDate = "1999-05-31" / >
    < / original >
    < / student >

    I know I could do with dbms_output.put_line tags, but I want to take full advantage of Oracle XML.
    Any help would be greatly appreciated.

    Published by: user9507990 on August 5, 2009 08:37

    OK, I probably messed up a bit with joins (got duplicates), but here's the idea:

    SELECT
    xmlelement("students",
     xmlagg(
      xmlelement("student",
                 xmlattributes(stu.student_id as "studentId",
                               stu.student_last_name as "lastName",
                               stu.student_first_name as "firstName"),
       xmlagg(
        xmlelement("sport",
                   xmlattributes(spo.sport_actc_code as "sportCode",
                                 spo.sport_term_code as "termCode")
        )
       ),
       xmlagg(
        xmlelement("award",
                   xmlattributes(awd.award_fund_code as "fundCode",
                                 awd.award_accept_amt as "awardAmount",
                                 to_char(awd.award_accept_date, 'YYYY-MM-DD') as "awardDate")
        )
       )
      )
     )
    )
    FROM students stu
         JOIN sports spo ON spo.sport_pidm = stu.student_pidm
         JOIN terms ter ON ter.term_code = spo.sport_term_code
         JOIN awards awd ON awd.award_aidy_code = ter.term_aidy_code AND awd.award_pidm = stu.student_pidm
    GROUP BY stu.student_id, stu.student_last_name, stu.student_first_name
    ORDER BY stu.student_id;
    

    The query uses the XMLELEMENT and XMLAGG to build the structure:
    The root element is 'students', to which we add several child nodes of "student".
    XMLATTRIBUTES is used to set the attributes of an element.

    Another solution would be to produce a "gross" in canonical format (...) xml document Oracle from using DBMS_XMLGEN this query:

    SELECT stu.student_id, stu.student_last_name, stu.student_first_name,
           spo.sport_actc_code, spo.sport_term_code,
           awd.award_fund_code, awd.award_accept_amt, to_char(awd.award_accept_date, 'YYYY-MM-DD') award_accept_date
    FROM students stu
         JOIN sports spo ON spo.sport_pidm = stu.student_pidm
         JOIN terms ter ON ter.term_code = spo.sport_term_code
         JOIN awards awd ON awd.award_aidy_code = ter.term_aidy_code AND awd.award_pidm = stu.student_pidm
    ORDER BY stu.student_id, spo.sport_actc_code, awd.award_fund_code;
    

    And then apply an XSL transformation to achieve the desired result.

    Hope that helps.

    Published by: odie_63 on August 6, 2009 14:44

Maybe you are looking for