Need to concat multiple elements into one element

Hello, here is my challenge:
Query:
SELECT  XMLROOT (
        XMLELEMENT ("Inv",
                         XMLAGG (
                                    XMLELEMENT ("Invline",
                                                 XMLELEMENT ( "Category", i.category ),
                                                XMLELEMENT ( "Amount", i.amount ),
                                     ), VERSION '1.0', STANDALONE YES).EXTRACT ('/*')
  FROM (
        SELECT 1 AS inv_no, 'Labor' AS category, 5 AS amount FROM DUAL
            UNION ALL
        SELECT 1, 'Out-of-Pocket', 10 FROM DUAL
            UNION ALL
        SELECT 1, 'Travel', 20 FROM DUAL
            UNION ALL
        SELECT 1, 'Travel', 2.5 FROM DUAL) i;
Returns:
<?xml version="1.0" standalone="yes"?>
<Inv>
  <Invline>
    <Category>Labor</Category>
    <Amount>5</Amount>
  </Invline>
  <Invline>
    <Category>Out-of-Pocket</Category>
    <Amount>10</Amount>
  </Invline>
  <Invline>
    <Category>Travel</Category>
    <Amount>20</Amount>
  </Invline>
  <Invline>
    <Category>Travel</Category>
    <Amount>2.5</Amount>
  </Invline>
</Inv>
Required:
<?xml version="1.0" standalone="yes"?>
<Inv>
  <Inv_No>1
    <Details>Labor 5
  Out-of-Pocket 10
  Travel 22.5
  </Details>
  </Inv_no>
</Inv>
So I would like help combining the details into one field for transmission to the Mexican Tax Authorities( their spec calls for all  invoice lines to be concated together).
Note that there are two travel details that need to be summed as well.
I would prefer to cannot change the query if possible, just using the XML functions.
Thanks!

And your db version is?
From 11.2 and onwards, you can use LISTAGG aggregate function to concatenate character data across rows :
SELECT XMLElement("Inv"
       , XMLAgg(
           XMLElement("Inv_No"
           , v.inv_no
           , XMLElement("Details"
             , listagg(v.category || ' ' || to_char(v.amount), chr(10))
                 within group (order by v.category)
FROM(
    SELECT t.inv_no
         , t.category
         , sum(t.amount) as amount
    FROM (
      SELECT 1 AS inv_no, 'Labor' AS category, 5 AS amount FROM DUAL UNION ALL
      SELECT 1, 'Out-of-Pocket', 10 FROM DUAL           UNION ALL
      SELECT 1, 'Travel', 20 FROM DUAL            UNION ALL
      SELECT 1, 'Travel', 2.5 FROM DUAL
    ) t
    GROUP BY t.inv_no, t.category
) v
GROUP BY v.inv_no ;

Similar Messages

  • How to concatenate multiple records into one

    Hi everybody:
    I want to know if exist some way to concat multiple records into one without using cursors. For example, I have a table named "Authors" like this:
    Lan|Author
    English|Ernest Hemingway
    Spanish|Octavio Paz
    Spanish|Mario Vargas Llosa
    English|Sinclair Lewis
    Spanish|Gabriel García Márquez
    And I want to get this:
    Author
    Octavio Paz, Mario Vargas Llosa, Gabriel García Márquez
    I have worked with SQL Server and I can do something like this:
    CREATE FUNCTION dbo.MyConcat (@lan varchar(10))
    RETURNS varchar(5000) AS
    BEGIN
    declare @retvalue varchar(5000)
    set @retvalue=''
    select @retvalue = @retvalue + Author +',' from Authors where lan = @lan
    return substring(@retvalue,1,len(@retvalue)-1)
    END
    ie, do not use cursors to concatenate records. However, with ORACLE, I have to do someting like this.
    FUNCTION MyConcat(P_Lan IN VARCHAR2) RETURN VARCHAR2 IS
    v_ret VARCHAR2(4000);
    v_element VARCHAR2(4000);
    v_cursor sys_refcursor;
    BEGIN
    OPEN v_cursor FOR SELECT Author FROM Authors where Lan = P_Lan
    LOOP
    FETCH v_cursor INTO v_elemento;
    EXIT WHEN v_cursor%NOTFOUND;
    IF v_ret IS NULL THEN
    v_ret := v_element;
    ELSE
    v_ret := v_ret || ', ' || v_element;
    END IF;
    END LOOP;
    RETURN v_ret;
    END;
    Exist some other way to do this?
    Best Regards
    Jack

    Tks both for answer... I forgot to mention that I am using Oracle 10g. I read about LISTAGG() but this function is available for Oracle 11g release 2.
    I wil read about the other techniques than Hoek mention
    Best Regards.
    Jack

  • How can I combine multiple pdfs into one document?

    I need to consolidate multiple docs into one.  How do I do that?

    It's pretty easy. Open multiple PDF documents in Apple Preview that came with your Mac. Choose View/Thumbnails so you can see the page thumbnail icons. Select any number (or all) of the page thumbnail icons of one document and drag them to any point in the thumbnails of another document.
    For example you can drag page 6 of one PDF between pages 40 and 41 of another PDF doc. But it sounds like you want to select all pages of one PDF and drag them to the end of another PDF doc.
    If you need more powerful document combining you can use PDFpen or Adobe Acrobat Professional, but they cost money.

  • What product do I need to just combine multiple pdfs into one pdf

    What product do I need to just combine multiple pdfs into one pdf. Thanks

    Are these files fillable forms?
    Could you need to combine more than 100 MB of files?

  • Merge multiple pictures into one picture like Photoscape?

    Looking for imac software like Photoscape which can merge multiple pictures into one.  Thanks!

    PhotoShop Elements is a good one
    LN

  • Scanning multiple pages into one document with an automatic document feeder

    when using automatic document feeder to scan in multiple pages - using the Image Capture app, this process does not work for more than 2 pages. However works perfectly in PC environment.
    Using a MacBook Pro with 10.8.4 and a Lexmark Interpret 405S All In One Scanner.
    Is there any other all in one device that can perform this function in a Mac environment?
    Please advise.

    Hi @FentyFly ,
    I see by your post that you would like to know how to scan multiple pages into one file. I would like to help you out today.
    From the HP Scan Software, click on the link for Advanced Settings, then uncheck Create a separate file for each scanned page.
    Here is a URL for how to scan and change the settings. Just select your operating system.
    Scan.
    What operating system are you using? How to Find the Windows Edition and Version on Your Computer.
    If you need further assistance, just let me know.
    Have a great day!
    Thank You.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • How do I scan multiple pages into one pdf file using the PIXMA MG7520 on Windows 8.0? Please help!

    I recently received a PIXMA MG7520 for a gift.  It works great with my lenovo laptop/tablet running on Windos 8.0.  The one drawback to the HP all-in-one that it replaced is it does not have an ADF.  That being said, there must be some way to scan multiple pages into one pdf file.  I need help figuring thing out.  Thanks in advance!
    Solved!
    Go to Solution.

    Hi mdtolbert54,
    There is a program that comes with the printer called the IJ Scan Utility that can assist you with scanning multiple pages into a single PDF document.  To do this, please follow these steps:
    1. On your keyboard, press the Windows key.
    2. Start typing IJ SCAN UTILITY. The search window opens as you type. Once the IJ SCAN UTILITY is displayed, please select and open it.
    3. In the Canon IJ Scan Utility window that opens, click SETTINGS.... in the bottom right of the window. The Settings dialog box appears.
    4. Click the DOCUMENT SCAN option on the left pane of the window.
    5. In the SAVE SETTINGS section of the window, you will select the save format and location of the document you are about to scan.
    a.) In the FILE NAME field, specify the name you would like to give the file. By default the filename will begin with IMG; you can remove IMG and change it to whatever you would like to name the file.
    b.) In the DATA FORMAT field, use the drop-down arrow to select the PDF (Multiple Pages) option. 
    c.) In the SAVE IN field, please navigate to the area where you would like the file to be saved once it is scanned in. By default, the file will be saved in the MY DOCUMENTS folder.
    6. Once all settings have been selected, click the OK button at the bottom of the window to save the changes. The IJ Scan Utility main screen appears.
    7. Click the DOCUMENT button. Scanning starts. Click the CANCEL button to cancel scanning if needed. Scanned items are saved in previously selected folder location specified in the SETTINGS... window.
    If you find that you need advanced scanning options such as adjusting resolution, brightness, contrast, saturation, color balance, etc. in addition to the options selected above, please click on the SCANGEAR button on the IJ Scan Utility Main screen, then adjust the items as necessary.
    Once the items above are set for document scanning, in the future, you will only need to launch the IJ Scan Utility, then press the DOCUMENT button to perform the scan (unless you want to make changes to the settings).
    Hope this helps!
    This didn't answer your question or issue? Please call or email us using one of the methods on the Contact Us page for further assistance.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • How do I scan multiple pages into one document using the CanoScan LiDE 200?

    How do I scan multiple pages into one document using the CanoScan LiDE 200?
    I can't seem to find a way to get them to scan continuously, or a way to stitch them together afterwards.

    Hi dagda24,
    You can scan multiple pages into a single document with the scan to PDF option.  Use the following steps to do so:
    1.  Open MP Navigator.
    2.  Click One Clcik.
    3.  Click Save to PC.
    4.  Change the File Type from PDF to PDF (multiple pages).
    5.  Make any other changes as needed, then click scan.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • Problem in Showing multiple values into one text box.

    Hi all,
    How can show i multiple row values into one text box. here text box is multi line type.
    i have one table it has content column, it has number of rows. i need to show those data into one text box in form. how can i solve it?
    my sample code here,
    egin
    --:block3.txt_to := :parameter.p_current_user||''||':'||:block3.txt_From;
    -- go_item('txt_from');
    insert into chat(fromid,toid,content)values(:block3.fromid,:block3.toid,:block3.txt_From);
    :block3.txt_From:= null;
    commit;
    :block3.txt_to := :parameter.p_current_user||''||':'||:block3.txt_From;
    go_item('txt_from');
    declare
    cursor c4 is select content from chat where toid = :block3.fromid;
    rec1 c4%rowtype;
    begin
    open c4;
    loop
    fetch c4 into rec1;
    exit when c4%notfound;
    null;
    end loop;
    end;
    --select content into :block3.txt_to from chat where toid= :block3.fromid;
    end;
    please give me some tips to solve it.
    thanks
    gurus

    Hi,
    Try giving CHR(10) for line feed.
    DECLARE
         CURSOR C4 IS SELECT CONTENT FROM CHAT WHERE TOID = :BLOCK3.FROMID;
         Str_Temp VARCHAR2(20);
    BEGIN
         :BLOCK3.TXT_TO := '';
         OPEN C4;
         LOOP
              FETCH C4 INTO Str_Temp;
              EXIT WHEN C4%NOTFOUND;
              :BLOCK3.TXT_TO := :BLOCK3.TXT_TO || CHR(10) || Str_Temp;
         END LOOP;
         CLOSE C4;
    END;Regards,
    Manu.
    If this answer is helpful or correct, please mark it. Thanks.

  • Export multiple tables into one flat file

    I have data in multiple tables on a processing database that I need to move up to a production database. I want to export the data into a flat file, ftp it to the production server and have another job pick up the file and process it. I am looking for
    design suggestions on how to get multiple tables into one flat file using SSIS?
    Thank You.

    Hey,
    Without a bit more detail, as per Russels response, its difficult to give an exact recommendation.
    Essentially, you would first add a data flow task to your control flow.  Create a source per table, then direct the output of each into an union all task.  The output from the union all task would then be directed to a flat file destination.
    Within the union all task you can map the various input columns into the appropriate outputs.
    If the sources are different, it would probably be easiest to add a derived column task in-between the source and the union all, adding columns as appropriate and setting a default value that can be easily identified later (again depending on your requirements).
    Hope that helps,
    Jamie

  • How do I turn off automatic bookmark creation when combining multiple PDFs into one?

    When I combine multiple PDFs into one, I need Adobe to use the CUSTOM bookmarks I created in the original PDFs. I do NOT want the additional PDF name as a bookmark in this instance. Is there a way to turn this option OFF in Acrobat Professional? I have version 9.

    You can not automatically turn off this action nor can you remove the 'file_name.pdf' heading, but you could add a button or menuitem to remove the 'file_name.pdf' from the bookamarks. Yes, it is one more step to perform when combining PDFs, but is you want until you have all of the PDFs combined you only need do it once.
    Removing filename bookmarks created by Acrobat by Sean Stewart
    From the above article:
    "With the release of Acrobat 6 came the ability to create a composite (binder) document from multiple files, (i.e. File > Create PDF > From Multiple Files.) When this is done, Acrobat automatically inserts a new top level bookmark at the start of each new file. The bookmark title will correspond to the source filename of the source file. While this level of separation can be helpful, it is counterproductive when the user wants the bookmark tree in the merged document to be continuous.
    "Here's a sample JavaScript to remove the top level bookmarks from the bookmark tree. This script will look for a ".pdf" extension to decide whether to remove the bookmark."
    With some additional coding you can add menu item or toolbar button.

  • Combine multiple drawings into ONE SHEET

    Hello, this is a question on Acrobat Pro, ver 8, using Windows XP. I guess I understand how to combine multiple files into a single PDF-file. However, this morning I happened to see the option mentioned in the subject line. When you go to "Combine files" > "Getting started with combined files" and select "CAD drawings" the description reads: "Combine multiple drawings into one sheet that's easy to navigate and print". How can this be done? I need to combine 8 ea CAD drawings (already converted to PDF) into ONE SHEET for printing without having the need taping 8 pieces of paper together. Arranging the drawing within the CAD application is not an option because the files were delivered by a 3rd party company and they only deliver PDFs

    Hi Priya,
      You can do this by merging the requets.
       1. goto Se10 and right click on the request and seelct merge requests.
       2. It will ask you from request and to request. Give the request names.
       3. After merging first request contents will be added to second request and
           first request will be deleted.
      Like that you can merge 3 requests to one request.
      Let me know if you want more info.  
    Thanks & Regards,
    Siri.

  • Text issues merging multiple pdfs into one pdf

    Hello, when I merge multiple pdfs into one pdf document my text is missing or garbled.  I spent hours yesterday trying to figure this out, from insuring the text was embedded and print setting were correct.  Please help!!
    Using Adobe Pro 9.0
    Thanks,
    Faith

    Acrobat Pro is the application you use for working with PDFs, making minor edits, combining multiple PDFs into a single file, extracting or replacing pages, doing fancier form work than ID has the ability to produce, and even creating PDF from a number of other file formats. I'm not sure your question about maintaining the quality of your photos is really applicable -- it would depend on how youare getting from the photo to PDF to begin with. The use of Acrobat in and of itself won't be the determiner.
    That said, I couldn't live without Acrobat Pro in my workflow. Since you are on CS5.5 you have a couple of options. You could purchase a subscription to Creative Cloud (at a discount for the first year), which would give you access not only to Acrobat, but all of the other programs and tools included in the suite, but you pay a monthly or yearly fee, or you can buy a standalone perpetual license to either Acrobat Pro or Acrobat Standard (I didn't realize Standard was still an option, and you might not need all the features of Pro -- you can compare at http://www.adobe.com/products/acrobatpro/buying-guide.html).

  • How do I scan multiple pages into one pdf document on a HP Envy 4501 Printer

    My HP Envy 4501 Printer won't let me scan multiple pages into one pdf document.
    I went to "Advanced Settings", clicked on "file" and made sure that the check box next to "Create a separate file for each scanner page" was unchecked.
    When I clicked the Save button it showed the page that I scanned and showed 1/1.  On the right side it had options for changing the brightness and Contrast, Rotate and Crop and "Back", "Save" and "Done" buttons, but nothing about scanning another page.
    Not to mention HP's Customer Support is useless!
    I'd appreciate any help I can get with this problem.
    Thanks,
    Mark

    Hi BH,
    I see your diagram.  I just scanned something.  The screen that I'm looking at right now shows the preview page and the scroll box to the left of that just like in your diagram.  The screen does not show the + button nor does it show the red x button under the scroll box as in your diagram.  I can't see the plus sign because it is not there.
    I tried re-installing the software and drivers as you suggested but that did not have any affect.
    Thank you for trying to help me with this problem but it hasn't worked, therefore I can't mark the reply "Accept as Solution".
    I've noticed that on HP's support forum web page there is only 1 solved request for assistance.  That doesn't give me much confidence in HP.
    Please reply back to this post to let me know if there is anything else that I can try or if you know someone else at HP that can help.
    If I don't here back from you, I'm returning this HP Envy 4501 Printer to get my money back to use it to buy a printer from one of HP's competitors.
    Thanks,
    Mark  

  • Scaning multiple pages into one file on a 4630

    Using HP 4630 printer, windows 8.1, wireless connection.
    Want to scan multiple pages into one file.
    Per user manual, I work from the computer not the printer.
    When first page is scanned am asked if I want to save, I click yes and name file.
    When I scan second page am again asked if I want to save, my file name appears, I am told it already exists and asks if I want  to keep or replace it.
    Whichever one I click, only the second page is saved.
    What am I doing wrong?
    Question: How do I scan mutiple pages into a single document?
    This question was solved.
    View Solution.

    I accept this solution with many thanks!  It was so obvious and I didn't see it.  The User Manual should mention this.

Maybe you are looking for

  • Please help me...major issues with authorized repair center

    I could really use the advice of those more "techie" than myself. About a month ago, my iBook G4 crashed on me. I brought it to an authorized repair center and they replaced the hard drive for $270. When I got it home, it seemed to be acting funny -

  • Maxl Import Dimensions

    Hello, I need implement a maxl script to load member in essb 9.3.1 LOGIN user pass ON server; IMPORT DATABASE app.db DIMENSIONS From LOCAL TEXT DATA_FILE 'G:\\Produc.txt' ---client folder USING SERVER RULES_FILE 'PrdPearl' ON ERROR APPEND TO 'G:\\er_

  • Microsoft project for mac

    is there an = to microsoft project for mac?

  • Need help with log in (says i have no device registered - but I do!)

    I've somehow lost my iphone 5 - and really need to use find my iphone in icloud...but when I try to log in, I can't get past this message.  The thing is, I've used this feature before...and my phone was definitely set up.  Does anyone have any sugges

  • Fan running constantly since installing Yosemite

    Since upgrading (...) my MacBook Air (mid 2013) to Yosemite, the fan is going more or less constantly. I've reviewed a few posts, and emptying Safari cache didn't do it for me. Any ideas?