groups nested without group xmlagg function

I make groups nested without group xmlagg function when using the xmlagg inside another function xmlagg function. Find the structure and sample data in the table here.
 CREATE TABLE "TEST_TABLE" 
   ("KEY" NUMBER(20,0), 
    "NAME" VARCHAR2(50 ), 
    "DESCRIPTION" VARCHAR2(100 )
   );

   Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (1,'sam','desc1');
   Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (2,'max','desc2');
   Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (3,'peter',null);
   Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (4,'andrew',null);

select 
        XMLSerialize(document
        xmlelement("root",
         xmlagg(
           xmlelement("emp"           
           , xmlforest(Key as "ID")           
           , xmlforest(name as "ename")
           , xmlelement("Descriptions",  
           xmlagg(
              xmlforest(description as "Desc")
              )
            )
           )
          )
       ) as clob indent
       ) as t    
      from test_table;
Then I removed the of the select query above and utilisΘ xmlelement xmlagg function
  select 
        XMLSerialize(document
        xmlelement("root",
         xmlagg(
           xmlelement("emp"           
           , xmlforest(Key as "ID")           
           , xmlforest(name as "ename")
           , xmlelement("Descriptions",             
              xmlforest(description as "Desc")
              )           
           )
          )
       ) as clob indent
       ) as t    
      from test_table;
It works fine, but the created xml with empty elements for Descriptions key 3 and 4 that has null values. I need no need descriptions element in the xml file when it is set to null. Please help me solve this problem.

Expected behavior, it is not a bug.

The real question is why did you put XMLAgg in the first place?
You can expect several DESCRIPTION by employee?

If yes then please provide some examples of data to this situation.
If not then a simple case statement should be enough:

SQL> set long 1000
SQL>
SQL> select XMLSerialize(document
  2          xmlelement("root",
  3           xmlagg(
  4             xmlelement("emp"
  5             , xmlforest(Key as "ID")
  6             , xmlforest(name as "ename")
  7             , case when description is not null then
  8                xmlelement("Descriptions",
  9                  xmlforest(description as "Desc")
 10                )
 11               end
 12             )
 13           )
 14          ) as clob indent
 15         ) as t
 16  from test_table;

T
--------------------------------------------------------------------------------

  
    1
    sam
    
      desc1
    
  
  
    2
    max
    
      desc2
    
  
  
    3
    peter
  
  
    4
    andrew
  

 

Tags: Database

Similar Questions

  • Functions nested without waiting

    var confirmed = confirm ("You picked [ " + selected_rbutton (totalgroups) +" ]"+ "\nYou picked [ " + questionResize (rsizechoice) + " ] to resize" + "\n" +"\nContinue?");
            confirm.noAsDflt == false;
            
            if (confirmed == true)
            {
                copy();
                openTemp ();
                paste();
                centerArt ();
                resizeart ();
                savefile ()
                putname ();
                
             } /*end if */ else
         {
             alert ("You chose not to continue, script stopped")
             }//end else
    }//end if OK
    

    I coded everything inside separate functions in this way I can save space, leaving the user to make a choice, and each choice will use different groups of functions.  My only problem is that some functions still doing their thing when the next begins, but it can depend on the one above it at the end.  Function savefile () lets the user type in a new name and saves it to a couple of different folder then putname () Function puts the user name and the name of the file in the top of the artboard in the corner.  What is happening is that the user is chooseing to rename the file but the putname () function has already filled its variables with the old name not a new one.  How can I make him wait until the function savefile () is done?

    putname() must not start before the end of savefile(), if necessary, would be a way to make him wait

    var wait = false;
    var a = 0;
    
    wait = savefile();
    
    while(!wait) {
    
        //wait = false; // this is just killing time
        a++; // so is this  
    
        if (a>1000) break; // guard against infinite loop
    }
    
    putname();
    
    function savefile() {
        // do your thing
    
        return true;
    }
    
    function putname() {
        alert('finally!');
    }
    
  • manifest files can be deleted without affecting the functions of the computer?

    Manifest files can be deleted without affecting the functions of the computer?

    Hello

    1. you try to delete a specific file?
    2. Why are you trying to delete the manifest files?

    Please answer these questions that might help us helping you better.

  • Upgrade to LR5.7 and PS Elements 13.  With the help of an SSD that is more complete! Can I remove older versions of these programs without affecting the functionality of the new programs?

    Upgrade to LR5.7 and PS Elements 13.  With the help of a Solid State Drive, which is more complete! Can I remove older versions of these programs without affecting the functionality of the new programs?

    Yes, there is no need to keep older versions of the software on the SSD (or your computer).

    In addition, you mentioned but if the photos are on the SSD, you must move them off the SSD for a typical hard drive, by following these instructions: Adobe Lightroom - find folders and files moved or missing

  • How can I access a chronology nested without a double click

    I edited video clips in my calendar nested and clicked on to the home page.  I can see no longer the movie clip on the main timeline and therefore I can't access nested timeline for changes.  Is it possible to access my calendar nested without a double click on the clip?

    Thank you

    Double-click the symbol in the library

  • I want the single update query without using the function.

    I want to update sells_table selling_code field with product_code date product table max.
    In the product table, there are several product_code date wise.

    I did with below charly with the use of the service, but we can do in the query what a single update
    without using the function.

    UPDATE sells_table
    SET selling_code = MAXDATEPRODUCT (ctd_vpk_product_code)
    WHERE NVL(update_product_flag,0) = 0;

    (P_product IN VARCHAR2) RETURN of HVL.maxdateproduct NUMBER FUNCTION to CREATE or REPLACE
    IS
    max_date_product VARCHAR2 (100);
    BEGIN
    BEGIN
    SELECT NVL (TRIM (product_code), 0)
    IN max_date_product
    FROM (SELECT product_code, xref_end_dt)
    PRODUCT
    WHERE TO_NUMBER (p_product) = pr.item_id
    ORDER BY xref_end_dt DESC)
    WHERE ROWNUM = 1; -He'll be back a single line - max date product code
    EXCEPTION
    WHILE OTHERS
    THEN
    RETURN 0;
    END;

    RETURN max_date_product;

    END maxdateproduct;

    Thanks in advance.

    Hello

    Something like that.

    update setlls_table st
            set selling_code =(select nvl(trim(product_code)) from
                                  (select product_code
                                          , rank() over (partition by item_id order by xref_end_dt DESC) rn
                                       from product
                                   ) pr
                                   where rn =1
                                         and pr.item_id = st.ctd_vpk_product_code
                               ) where NVL(update_product_flag,0) = 0 ;
    

    That such is not tested due to lack of sampling input.

    Concerning
    Anurag Tibrewal.

  • Grouping SQL functions

    Hello

    My sql query returns this data below:


    Column 1 column 2of the _ _ column 3
    A, B AND C
    A B D


    I want this way:


    Column 1 column 2of the _ _ column 3
    B, C, D



    How to group these data in two rows column which is common and separate the few with comma delimited values and show the result...?

    user9021545 wrote:
    What is here C-online rtrim(xmlagg(xmlelement(c,c3,',').extract('//text () ') order of c3), ',') c3_list?

    As in most cases, it helps when you read the documentation:

    XMLELEMENT. In any case, it's just a name assigned to the element. You can call it pretty much anything (in oracle naming rules):

    SQL> with sample_table as (
      2                        select 'A' c1,'B' c2,'C' c3 from dual union all
      3                        select 'A','B','D' from dual
      4                       )
      5  select  c1,
      6          c2,
      7          rtrim(xmlagg(xmlelement(user9021545,c3,',').extract('//text()') order by c3),',') c3_list
      8    from  sample_table
      9    group by c1,
     10             c2
     11    order by c1,
     12             c2
     13  /
    
    C C C3_LIST
    - - --------------------
    A B C,D
    
    SQL> 
    

    SY.

  • question about group by function

    Hello

    I need to know why when the clause is not used, and the having clause is used in the function group, can any one will contact

    When the clause is used to filter the lines in service come pathological column.
    He selects and filters-out of the lines in the table listed in the from clause.

    for example if you have a table with matching employees and departments, and you want to see all employees of departments 10,20,30,40 and 50; you will use this condition in where clause

    select
        dept_id, emp_id
    from
        employee
    where
       dept_id in(10,20,30,40);
    

    Now let's say you want to check the number of employees in these departments

    select
        dept_id, count(emp_id)
    from
        employee
    where
       dept_id in(10,20,30,40)
    group by
       dept_id;
    

    now, if you need to select only the departments that have more than 1000 employees in them, your query will look like this:

    select
        dept_id, count(emp_id)
    from
        employee
    where
       dept_id in(10,20,30,40)
    group by
       dept_id
    having count(emp_id) > 1000;
    

    Here the condition where clause filters out all departments other than 10,20,30,40,50; the condition that must be applied for further filtering some departments on a per employee basis, cannot be applied in the where clause as it should be applied after + the function group worked on the rows of the table; After calculating the number of employees in each Department. Where the need for the clause which is evaluated after the group by the having clause.

    I hope this helps.

  • Unable to get the database searched with MAX and GROUP BY function

    Hello
    All the

    I have a table as below:
    COLUMN TYPE
    User_id VARCHAR2 (10 byte)
    ID_processus VARCHAR2 (30 bytes)
    END_TIME DATE (STAMP)
    TO_LOC VARCHAR2 (12 bytes)
    TO_LOC_TYPE VARCHAR2 (15 bytes)
    FROM_LOC VARCHAR2 (12 bytes)
    ITEM_ID VARCHAR2 (25 bytes)
    CASE NUMBER (12.4)
    LMS_UDA1 VARCHAR2 (250 bytes)
    AREA VARCHAR2 (2 bytes)

    I only want to get one record with all the columns, have only one clause MAX (END_TIME)
    But the other column value of the difference.
    When I use MAX (END_TIME) and GROUP OF USER_ID, ID_processus, CASE...
    the sql did not a single record,
    It gives the number of records

    Please help me on this

    Concerning

    Saven

    >
    I only want to get one record with all the columns, have only one clause MAX (END_TIME)
    But the other column value of the difference.
    >
    Maybe it's not possible because it depends on your data.

    If the combination of all columns except END_TIME is not unique then there will be multiple records; a record for each unique combination (GROUP BY) of all other columns.

    The only way to ensure that a record is

    SELECT MAX(END_TIME) FROM myTable
    
  • I have TWO Microsoft Visual C++ - 2005 - I can remove the SMALL program without damaging my functions

    There is no installation date, they are the same description but more smaller sizes can so I guess the smaller version is an older version and delete it without affecting my use

    Hello

    1. why would you want to remove it?
    2. they offered as Windows updates?

    If they are installed successfully, I would not recommend you to uninstall, because it can cause your computer is not functioning normally. It is always advisable to keep your computer up-to-date with the latest Windows updates installed.

    See also:
    http://Windows.Microsoft.com/en-us/Windows/help/Windows-Update

  • Validation of DateTime field (without custom management functions)

    Hello

    I need to know how I can validate if a date is correct or not and fail to do something.

    I have a DateTime Field field, with a pattern ' DD / MM / YYYY ', the value appears correctly using the selected template, the problem is validation.


    Now I just that if the date is wrong, teaches an alert to the user, and the focus returns to the DateTime control until you enter a valid value.

    I need something like:

    -Form1.SUBVENCION_O_AYUDA.dateTimeField1: Validate - (JavaScript, client).

    If (this.rawValue! = null & &! test (this.rawValue, ' DD/MM/YYYY')) {}

    xfa.host.setFocus ("this");
    }

    How will I know if the validation is successful or not (without having to implement long-standing management functions)?

    By default, if I put 'validation model messaga' field, a warning message is displayed, but here the emphasis is more and the user can continue to fill the rest of the form, whereas the datetime field is filled with an incorrect value.

    I want to warn the user to continue to fill out the form, if the value in the dateTime field is not valid.

    Any idea?

    Thank you!

    Hello

    If your date may not be formatted correctly against your view model then the formattedValue is equal to the rawValue.

    Thus, in the event output put;

    If (this.rawValue is this.formattedValue)

    {

    App.Alert ("enter a date in the dd/mm/yyyy" format "");

    xfa.host.setFocus (this.somExpression);

    }

    Bruce
  • How display you continuous data in real-time without sacrificing the functionality of control of users?

    Hello

    I created a vi (see table) that displays a signal when the user selects the start/stop button. The user can interrupt the signal by selecting the same button. "Gathering" and "stop collect" buttons each screen a message when selected, and the button "exit" to stop the vi.

    What I want to do: create a user will be able to start/stop the signal and be able to call the functions from the 'collect', 'stop collect' and 'Quit' buttons, no matter what state the start/stop signal is in.

    What is actually happening: buttons work if not selected in a specific sequence. For example, by clicking on the 'stop collect' button then the ' start/stop' button, the signal will not appear. But reverse the order and the signal is displayed.

    Why the loop containing the Simulator signal interfere with the loop that contains my structure of the event for my buttons? I'm using Labview 2013.

    No, this loop ends. In your diagram, it starts when your program does (although you should also press the start/stop button to generate data), and once he is arrested, there no way to start it again.

    Cameron

  • Cannot save in JPG format without loss of functionality

    When I draw a "text box, draw draw or a draw oval arrow' and try to save it as a JPG file, it saves the background image ONLY and delete all the other features of the PDF. I use the settings by default and without layers. So the question is: "how to save a PDF file as a JPG in Adobe Acrobat X without losing all added adobe content? Thank you!

    Using Acrobat Pro preflight flatten annotations.

  • You can load a new versions of adobe on top an old version without loss of functionality?

    The user has Adobe standard 10.  She just bought Adobe 11 pro.  can she keep 10 and install 11 on top?

    Although don't completely prevent us this installation, the fact is that at Adobe we most recommend against this. Over the years, we have seen far too many users problems enter trying to have such parallel facilities.

    Because Acrobat interacts with the system (the Adobe PDF PostScript printer driver instance) drivers and applications (the Office PDFMakers and other applications), unlike other applications such as Photoshop or Illustrator Adobe, you cannot maintain full functionality for both versions and unless the old version is totally deleted, you may encounter conflicts.

    If you try to use both versions for some type of goal company tests, we strongly recommend that you do with VM (virtual machine), one with Acrobat Standard 10 and the other with Acrobat Pro 11.

    -Dov

  • In a paragraph style of nesting "without breakage?

    (My apologies if this has been requested and we have responded).

    Is it possible to set my body copy paragraph style to apply automatically "without interruption" for the last two words in the paragraph?

    I'm pretty good on the digitization of text in search of paragraphs that ends with a small hooked at the end Word, but it would be nice to automate it.

    Another solution would be to set a minimum word count allowed on a single line. (Not useful for subtitles!)

    Thank you.

    I also like this one, published some time ago by another reader (sorry, I don't remember which):

    1 create a character with the single attribute being without breaking Style.

    2. create a new paragraph and in the GREP Style column, the menu drop-down Style "Style", choose the character style, that you just created.

    3. in the box "to text", enter this: {15} $

    The number in brackets (in this case 15) can be any number and represents the minimum number of characters - including spaces - appearing on the last line of a paragraph. Very convenient when you want to eliminate the orphans!

    See you soon!

    -Mikey

Maybe you are looking for