A very basic sql xml question..

I want to print only two rows group by grup number so there are only two group numbers
0 and 1...
so 0 group should have two items...
Elapsed: 00:00:00.01
15:15:55 SQL>
15:15:56 SQL> l
  1  with data as
  2    (select 0 as grp,'A' item_name , 'XX' Item_desc from dual
  3     union
  4      select 0 ,'B'  , 'XY'  from dual
  5      union
  6      select 1 ,'B'  , 'Y'  from dual
  7       )
  8  select xmlelement(name "grp",
  9            xmlforest(grp  "item_name",item_name)
10            )
11*  from data
15:15:57 SQL> /
XMLELEMENT(NAME"GRP",XMLFOREST(GRP"ITEM_NAME",ITEM_NAME))
<grp><item_name>0</item_name><ITEM_NAME>A</ITEM_NAME></grp>
<grp><item_name>0</item_name><ITEM_NAME>B</ITEM_NAME></grp>
<grp><item_name>1</item_name><ITEM_NAME>B</ITEM_NAME></grp>
Elapsed: 00:00:00.01

Hi,
You should use XMLAGG, to get everything into a single XML element. And DON'T use extract()!!
Something like:
SQL> declare
   xml   xmltype;
begin
  with data as
    (select 0 grp, 'g1' grp_name, 'A' item_name, 'XX' item_desc from dual union all
     select 0    ,  'g1' grp_name,'B'          , 'XY'           from dual union all
     select 0    ,  'g2' grp_name,'B'          , 'XY'           from dual union all
     select 0    ,  'g3' grp_name,'B'          , 'XY'           from dual union all
     select 1    ,  'g1' grp_name,'B'          , 'Y'            from dual)
-- end of test data    
     select xmlagg(xmlelement("GRP"
                             ,xmlagg(xmlelement("ITEM_NAME", item_name))
                             ,xmlagg(xmlelement("item_desc", item_desc))))
       into xml
       from data
   group by grp, grp_name, item_name;
   dbms_output.put_line(dbms_lob.getlength(xml.getclobval()));
end;
299
PL/SQL procedure successfully completed.Regards
Peter

Similar Messages

  • Very basic SQL/XML question

    I'm using the following environment:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE 10.2.0.1.0 Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    However, I don't think my environment is the issue.
    I'm trying to get output which looks like this from a simple table:
    <MAXDOMAIN action="S">
         <DOMAINID key="true">domainid_data</DOMAINID>
         <SYNONYMDOMAIN type="relationship" action="AU" >
              <VALUE key="true">value_data</VALUE>
              <MAXVALUE>maxvalue_data</MAXVALUE>
              <DESCRIPTION>description_data</DESCRIPTION>
              <DEFAULTS>defaults_data</DEFAULTS>
         </SYNONYMDOMAIN>
    </MAXDOMAIN>The table looks like this
    Name                           Null     Type          
    DOMAINID                       NOT NULL VARCHAR2(30)   
    DESCRIPTION                             VARCHAR2(50)   
    DOMAINTYPE                              VARCHAR2(5)    
    MAXTYPE                                 VARCHAR2(5)    
    LENGTH                                  VARCHAR2(5) The real question is how do I get an element with attributes to also have content.
    <DOMAINID key="true">domainid_data</DOMAINID>and
    <VALUE key="true">value_data</VALUE>I'm not sure if I'm syntactically challenged or just not using the correct tags.
    If I try to just generate the first two tags, forgetting the following nesting, I'm OK, as long as I don't try to assign attributes to the DOMAINID tag:
    SELECT  XMLELEMENT
    ("MAXDOMAIN",XMLATTRIBUTES('S' AS "action"),XMLELEMENT(NAME DOMAINID, "DOMAINID")
    AS "RESULT"
    FROM FAC_MAXDOMAIN;This works and is pretty trivial.
    <MAXDOMAIN action="S"><DOMAINID>AIRFLOWTYPE</DOMAINID></MAXDOMAIN>
    etc, etc...However, this:
    SELECT  XMLELEMENT
    ("MAXDOMAIN",XMLATTRIBUTES('S' AS "action"),XMLELEMENT(NAME DOMAINID, "DOMAINID",XMLATTRIBUTES('true' AS "key"))
    AS "RESULT"
    FROM FAC_MAXDOMAIN;Yields an ORA-00907: missing right parenthesis error.
    Any ideas? maybe a good primer on SQL/XML might be the best solution...
    TIA,
    Paolo

    Very nice for a first post in terms of data included and formatting.
    It took me a few minutes to see it, but the simple answer is you are putting the XMLAttributes in the wrong location. See the XMLElement spec at http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions220.htm#SQLRF06168 that shows XMLAttributes comes between the identifier and value. So that means you should have written it as
    Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.6.0
    SQL> WITH FAC_MAXDOMAIN AS
      2  (SELECT 'domainid_data' domainid, 'dscr' description,
      3          'type' domaintype, '10' maxtype, '5' length
      4     FROM dual)
      5  -- Using WITH so didn't have to create your table locally
      6  SELECT  XMLELEMENT("MAXDOMAIN",
      7            XMLATTRIBUTES('S' AS "action"),
      8            XMLELEMENT(NAME DOMAINID, XMLATTRIBUTES('true' AS "key"), "DOMAINID")
      9          )
    10  AS "RESULT"
    11  FROM FAC_MAXDOMAIN;
    RESULT
    <MAXDOMAIN action="S"><DOMAINID key="true">domainid_data</DOMAINID></MAXDOMAIN>

  • A very basic editor related question

    Dreamweaver is considered a versatile & matured HTML editing tool, but (surprisingly) I could not find a very basic HTML editing facility in Dreamweaver (which is found in some free tools like Aptana Studio).
    In the code editor, if I click on a HTML (starting) tag, the editor should highlight the end tag, but the Dreamweaver editor does not do that? Am I missing anything?
    (I am using Dreamweaver CS3)

    In Code View you have some icons on the left side of your screen.  These can be used to expand and collapse sections of code for easier viewing.
    < > Select Parent Tag.  See screenshot.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb
    http://alt-web.blogspot.com

  • 2 very basic sql questions (I hope)

    Hi;
    This is for the ADO.NET 2.0 MS Oracle driver. Is there a standard way to do either of the following:
    Sql Server has the concept of getting the first N of a select only using:
    select top 1 * from Schedule where deleted = 0 order by runNext
    Does Oracle have this and if so, what is the syntax please?
    Sql Server has the ability to return the value of an auto-generated primary key in the insert statement. In C# it goes like this:
    cmd.CommandText = "insert into Schedule (sTitle, sDescription) values ('my sched', 'all about it')";
    cmd.CommandText += "; select scope_identity()";
    object rtn = cmd.ExecuteScalar();
    return (long)(decimal)rtn;
    Is there a way to do this in Oracle and if so, how?
    thanks - dave

    1)
    select *
      from (select *
              from schedule
             where deleted = 0
             order by runNext)
    where rownum = 1;2)
    insert into Schedule (sTitle, sDescription)
      values ('my sched', 'all about it')
      returning pk_column_name into v_some_variable;Or, if the auto-generated value comes from a sequence, you can, after the insert:
    select my_sequence.currval from dual;

  • Very basic initial configuration question.

    Hi.
    I replaced a Catalyst 2960G for a C2960X-24-L in a network where there are already five switches.
    I have no idea how to assign it an ip : is there anyone here willing to explain that in  very simple way ?
    I tried plug it in the existing network, but didn't work.
    I'm not the one whom installed the network, and I'm doing that to help.
    Thank you.
    Pierre

    Also if you are adding a new sw to the network i recommend you to reset the vtp in that sw (if your network has it.) if you are not sure just do "vtp mode transparent" "vtp mode client" assuming that you are replacing a client sw.
    Then you should verify before connecting to the network:
    - type of stp that your network is running
    - if you have vtp check the config and use the same domain, version, password so the sw gets the vlans from the 
    - when you have all the vlans set in the sw then add the interfaces to the vlans
    - be sure that you are not replacing the root sw.
    Maybe there are others things to check but thats what comes to my mind now
    Regards

  • Very Basic ISA 2006 Question

    I am the first to admit that I don't really know anything about ISA....so please forgive me if this question is too stupid for words.....(and if a particular MVP with the initials 'AF' is reading this, then yes, I know I am incredibly stupid and shouldn't have
    anything to do with networks, and me posting to these forums is an offence to your sensibilities etc etc, so spare me the rant this time...)
    Anyway, I was under the impression that with ISA server you could have a number of web sites all running off the same IP address. For example, we have 2 websites (site1.company.com and site2.company.com) and 1 external IP address. We have DNS records set up
    for each of these sites, and they both point to our external IP address. What I thought happened (in my incredibly uneducated mind) was this
    1. User types www.site1.company.com into their browser, which resolves to our external IP address on our firewall. Our firewall forwards this request to our ISA s2006 server. The ISA server reads the 'site1.company.com'
    in the request and forwards the traffic to webserver1.
    2. User types www.site2.company.com into their browser, which resolves to our external IP address on our firewall. Our firewall forwards this request to our ISA s2006 server. The ISA server reads the 'site2.company.com'
    in the request and forwards the traffic to webserver2.
    Are my assumptions correct, or do we need a public IP address for every site we wish to publish?

    Hi,
    you are correct. It is possible to publish multiple websites with one public IP address:
    http://support.microsoft.com/kb/838252/en-us
    http://blogs.technet.com/b/isablog/archive/2008/06/19/another-look-at-web-publishing-part-ii-host-headers-with-ssl-and-certificates.aspx
    regards Marc Grote aka Jens Baier - www.it-training-grote.de - www.forefront-tmg.de - www.galileocomputing.de/3570

  • Very basic user, simple question (i think)

    Hi there,
    Very new to dreamweaver, im making a website at the moment, what i dont understand is i have a set template, which i have used for about 6 pages within the website.  On all the pages it is very zoomed in when i preview it in chrome, apart from one page, this page looks perfect, its in perspective and everything isnt too large like on the others.  Is there a way i can make them all follow this one?
    Nevermind that, sorted that
    How do i set the zoom of the page, so when anyone goes onto the page it appears in the correct zoom, rather than far too zoomed in like it does now

    Newtimething wrote:
    Nevermind that, sorted that
    How do i set the zoom of the page, so when anyone goes onto the page it appears in the correct zoom, rather than far too zoomed in like it does now
    Not a clue what your'e talking about. Is the browser set to zoomed by default? Sometimes it can be set in the last position you use it at so you need to re-set it, that' a possibility

  • Very basic Objective-C Question

    Okay, I am completely new to Objective-C so forgive me.
    I am trying to run a command when the MainView is initially loaded, so I figured I would need to override the constructor. I tried overriding init and initWithFrame, but it didn't work.
    How can I get a command to run (sendDate = [NSDate date];) when the UIView is initially loaded?
    Thanks a bunch.

    Let's take a step back for a second. Are you using Interface Builder (IB) with XViewController?
    Usually with a UIViewController there is no separate UIView class. At least not with the code I've written. A view controller creates its own view. If using IB then the view is created from the XIB file. There is no actual UIView class on the file system or in your project.
    So what ends up happening is the UIViewController loads the view and the view controller's 'viewDidLoad' method gets called. It is usually here that you finish off setting up the view. You access the view using 'self.view' inside the view controller code.
    But you seem to have an actual class named MainView that is a UIView. And it appears that class has an instance variable of 'sendDate'. Did you create this class by hand? If so then you must have explicit code for creating it. Where is this code?
    This is one of those details that I could explain is 5 seconds in person after seeing what you were doing. But online I can't, of course, see what you are really doing.

  • Scripting Question - Very Basic

    Hello, I'm using the trial version of InDesign and am wondering if because it's the trial version that I can't load custom scripts from Adobe?  I've downloaded and installed a Custom Calendar script [I can see the extracted files in/on my PC] but the app apparently doesn't see it.  Any help you can offer is greatly appreciated.  Thanks, 

    Thank you so much, you were spot on. 
    From: Peter Spier <[email protected]>
    To: Friar5 <[email protected]>
    Sent: Monday, December 12, 2011 3:18 PM
    Subject: Scripting Question - Very Basic
    Re: Scripting Question - Very Basic created by Peter Spier in InDesign - View the full discussion
    Have you put thew script in a location that InDesign uses for scripts? See How to install scripts in InDesign | InDesignSecrets
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4079869#4079869
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4079869#4079869. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in InDesign by email or at Adobe Forums
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Basic Hyperion Workspace question

    Is there any way to Drill-Down to data by double-clicking on the chart item in Hyperion Workspace? I can do this in Hyperion Reporting Studio.

    hi all,Hi Neerav
    I have very basic clone database question
    If i create database A and clone database B using A...
    I want to know that any operation done on A will be automatically done on Cloned database B.Oops....Now you're asking about rocket science. Sorry, I don't know.
    I know about some basics:
    Streams or Replication--> Which can give you data on B in read-write mode.
    DR--> For safeguarding your database and B will work as DR solution.
    Hope u understandNo, please make us understand.
    Regards,
    S.K.

  • Basic recording/feedback question

    I'm recording basic vocals against accompaniment tracks using an APOGEE ONE and Audio-Technica 40 series AT8449 condenser mic. I use only headphones, no external speakers.
    If I record with "monitoring" on I constantly battle feedback/distortion, especially on songs with a wide dynamic range. When the feedback protection kicks in the message indicates that I'm getting feedback through my external speakers (which I don't have), I can minimize the problem by turning "monitoring" off but I lose the reference vocal. I know I must be overlooking something very simple. Any help is appreciated.

    hi all,Hi Neerav
    I have very basic clone database question
    If i create database A and clone database B using A...
    I want to know that any operation done on A will be automatically done on Cloned database B.Oops....Now you're asking about rocket science. Sorry, I don't know.
    I know about some basics:
    Streams or Replication--> Which can give you data on B in read-write mode.
    DR--> For safeguarding your database and B will work as DR solution.
    Hope u understandNo, please make us understand.
    Regards,
    S.K.

  • Basic PDF/SSL Question

    Okay, I know this is a basic question, and I'm not sure if this is really where I should be posting it, but maybe someone out there has experience with this.
    I have a PDF form sitting on a secure server.  I have it set up to email the completed PDF back to our company when the user clicks the SUBMIT buttton.  Whether or not the PDF is secure coming back to us would be dependent on the email server the user uses - not that the form sits in a secure area on our server or that the PDF is security settings are set, correct?
    Any input appreciated.
    Thanks
    Q

    hi all,Hi Neerav
    I have very basic clone database question
    If i create database A and clone database B using A...
    I want to know that any operation done on A will be automatically done on Cloned database B.Oops....Now you're asking about rocket science. Sorry, I don't know.
    I know about some basics:
    Streams or Replication--> Which can give you data on B in read-write mode.
    DR--> For safeguarding your database and B will work as DR solution.
    Hope u understandNo, please make us understand.
    Regards,
    S.K.

  • Basic Clone database question

    hi all,
    I have very basic clone database question
    If i create database A and clone database B using A...
    I want to know that any operation done on A will be automatically done on Cloned database B.
    Hope u understand
    Thanks,
    Neerav

    hi all,Hi Neerav
    I have very basic clone database question
    If i create database A and clone database B using A...
    I want to know that any operation done on A will be automatically done on Cloned database B.Oops....Now you're asking about rocket science. Sorry, I don't know.
    I know about some basics:
    Streams or Replication--> Which can give you data on B in read-write mode.
    DR--> For safeguarding your database and B will work as DR solution.
    Hope u understandNo, please make us understand.
    Regards,
    S.K.

  • VERY Basic Questions about Oracle eBusiness - what "languages" are used?

    Please forgive the very basic nature of this post- (I have been in systems (IT) for over 20 years, so I do have lots of systems experience, but no exposure to this particular software.)
    So here are the basic questions - I assume that much of the data base logic is written in PL/SQL, but what other tools / languages are the applications written in?
    (Oracle Forms, Oracle Reports, Java, C, something else?)
    With over 20 years and experience with a number of other packages, I can learn a great deal about an application by 1. Looking at the DB structures (charts), 2. looking into DB code (Packages, triggers, procedure, functions) and 3. Seeing the screen shots.
    None of my customers have had Oracle eBusiness - that have had home grown applications or other COTS/packages.
    can anyone suggest a place where an independent person can inexpensively get some exposure?
    My sincere thanks for any answers/suggestions. 

    Hi,
    Please refer to the following links for details about the different database releases and Oracle tools.
    Oracle Timeline
    http://www.oracle.com/timeline/index.html
    http://www.oracle.com/oramag/profit/07-may/p27anniv_timeline.pdf
    Oracle Corporation - Oracle FAQ
    http://www.orafaq.com/wiki/Oracle_Corporation
    Oracle E-Business Suite consists of Application/Database/Client tiers, you can find more details in [Oracle Applications Concepts|http://www.oracle.com/technology/documentation/applications.html] manual.
    Oracle Forms
    http://en.wikipedia.org/wiki/Oracle_Forms
    Regards,
    Hussein

  • If I upgrade to Mountain Lion on the computer that will install it, will my WIFI still work on the computer that cannot be upgraded? I know this is a very basic question

    If I upgrade to Mountain Lion on the computer that will install it, will my WIFI still work on the computer that cannot be upgraded? I know this is a very basic question. Trying to hold out as long as I can, but purchasing an iPhone for Christmas and new iMac next year when warrently expires.

    Thank U very much for the quick reply, I wanted to upgrade this weekend, but still on the fence. I can live with the software that is not compatible, they are on another compuetr, just didn't want the obvious stuff to stop working.

Maybe you are looking for

  • Kernel_Task High CPU Usage (300%) and Fan Speed - On Battery and Plugged In

    Hi Everyone, Came here to ask for help given my bad situation with MBA 13 Mid-2013 (Mavericks 10.9.2). Yesterday I`ve opened my MBA and it was very laggy and sluggish, and I could hear the fan going crazy on speed. After opening Activity Monitor, Ker

  • Laptop went for a swim, Help me get the contents of my time machined/boot camped hard drive back!

    So unfortunately my old 13" MacBook Pro got a drink spilled across it a few months back. Mr Genius at the Apple store took one look inside and shook his head "Catastrophic failure, It's hit the fan and gone everywhere". But it wasnt all bad news, He

  • Special Characters in the payload

    Hi, We are receiving Payload from Source Service Provider with some special characters “ and â€? as shown below: “Maintenance Documentation      Libraryâ€? under “Transformer Bushings Surveyâ€? Those Special Characters are actually double quote

  • IDE STUDIO CREATOR OR SWING

    I am new to development and started on VB where they had a GUI that was easy for me to learn. I was worried when I switched to JAVA, although I enjoy it I was worried about the GUI, until I found Studio Creator. Can you use Studio Creator for program

  • XML Tag in PHP Not Printing

    Hello Guys, I am using PHP 5 version and trying to print simple xml tag but its not wotking. The tag is echo '<markers/>'; . If i remove '>' i,e echo '<markers/'; its working fine. What could be the reason ? Thanks,