Limit the length of the result of the LISTAGG?

Is there a way to limit the length of the result of LISTAGG()?

I have two reasons for this:
-VARCHAR2 limit of 4000 bztes
-J' I need only the top 10 items (lines)

The query I use is:
select count(order_id) numOfOrders, order.store_id,  store.PhoneNr,
       LISTAGG( order_Id, ', ' ) WITHIN group ( ORDER BY Order_Id)  as first_ten_orders
     from t_orders order
     inner join store on store.store_id=order.store_id and (store.PhoneNr is not null )
     where order_status_id in (1,2,6) and order_date!=shipped_date
     group by order.store_id, store.PhoneNr;
This is a list of orders not shipped, grouped by stores (only those with phone numbers), listing the ID of the base, phone number, number of orders not shipped and the list of command IDS.

I want to restrict the list order ID, for example to the first ten items.

How can I do?

Is to use a function (custom) to cut the result string, but then, I would still have the first problem of VARCHAR2 length overflow in the case of many orders.

Hello

Here's one way:

You can use the analytic DENSE_RANK function to find who are the first 10 order_ids and a CASE expression allows to return the order_id for these 10 and null for all others. LISTAGG, like other aggregate functions ignore NULL values.

WITH     got_display_order_id     AS
(
     SELECT       COUNT (order_id)     AS cnt
     ,       order.store_id
     ,       store.phoneNr
     ,       CASE
                WHEN  DENSE_RANK () OVER ( PARTITION BY  order.store_id
                                                       ,            store.phonenr
                               ORDER BY      order_id
                                ) <= 10
                THEN  order_id
            END                           AS display_order_id
     FROM       t_orders     order
     JOIN       store               ON     store.store_id     = order.store_id
                               AND      store.PhoneNr      IS NOT NULL
     WHERE     order_status_id     IN (1, 2, 6)
     AND       order_date          != shipped_date
     GROUP BY  order.store_id
     ,            store.PhoneNr
     ,       order_id
)
SELECT    SUM (cnt)          AS numOfOrders
,        store_id
,       PhoneNr
,       LISTAGG (display_order_Id, ', ' ) WITHIN group (ORDER BY display_Order_Id)
                             AS first_ten_orders
FROM        got_display_order_id
GROUP BY  store_id
,            PhoneNr
;

If you would care to put a bit of data samples (CREATE TABLE and INSERT statements) and the results desired from these data, then I could test it.
To simplify the analysis, let's say you want to only see the first order_ids of 2 or 3. Change the results for 10 will be negligible.

Published by: Frank Kulash, 11 April 2012 10:37

Published by: Frank Kulash, 11 April 2012 10:46
The PARTITION that is added BY clause anlaytic DENSE_RANK.

Tags: Database

Similar Questions

  • How to limit the length of the texts on iOS9?

    Hello

    I just worked on why I am required by my mobile / cell phone provider EA.  They charge any text as a picture message / SMS, it is longer than 120 characters?  Does anyone know how to limit the length of the texts / SMS so that it is impossible to send a more 120 characters or create an alert so that you are aware of the number of characters in the text / sms?

    Thank you very much

    Hello Turnus123,

    Thank you for using communities of Apple Support.

    I see that you will have to pay for SMS more than 120 characters.  To help identify messages exceeds this amount, you can activate a number of characters in the message settings.  Simply go to settings > Messages and activate "number of characters".

    Message settings

    Take care.

  • limit the number of query results for content Presenter CMIS

    Hi dear,

    I have a problem. I added content present on my page in Jdev ide, not at run time. And I need a query including the limitation of the number of results.

    My query is: ${' SELECT * from ora: t:IDC:GlobalProfile WHERE the ora: p:xRegionDefinition =-"CSGMNEWS_REGDEF\" ORDER BY ora: p:dInDate DESC'}


    I just want to add a number parameter.

    Can you help me please? How can I limit the number of results?

    Kind regards

    Yacouba

    Published by: erdo on 21.Mar.2013 18:37

    Hello.

    Content Presenter has a setting (maxResults) to set the maximum returned results:

    Sample:

    xmlns = "http://xmlns.oracle.com/adf/controller/binding" Refresh 'ifNeeded' = >







    When you add your CP to a page at design time, you can access the pageDefinition and provide more values for attributes of CP.

    I hope this help you.

    Kind regards.

  • Limit the number of results when searching for users?

    Hi all.

    The following rule works very well:
      <invoke name='toList'>
        <invoke name='listObjects'>
          <ref>context</ref>
          <s>User</s>
          <map>
            <s>conditions</s>
            <list>
              <new class='com.waveset.object.AttributeCondition'>
                <s>DEFERREDTASKDATE</s>
                <s>notPresent</s>
                <s></s>
              </new>
            </list>
          </map>
        </invoke>
        <s>name</s>
      </invoke>
    But in the production environment, we want to limit the number of results to a manageable level, say 200 users. I tried resultLimit and LignesMax in the stock option plan, but nothing helped.
    Pointers to help me in the right direction?

    Best regards
    Stefan

    The JavaDoc for AttributeCondition does not list these operators or conditions.

    You will need to add conditions to your query that limits the response by other means.

    I don't know what your user name looks like, but for us, we have an ID for each account that you could put limits to

    i.e.

    UserID > current_place and userid< current_place="" +="">

    that, if the user name is a number, would limit the answer to a maximum of limit, but if no user is in the meantime it would obviously be zero.

    the alternative is to create your own rule to query the repository on your own and use the resulting data to browse normal calls.
    It's a bit heavy if you use attributes that are not available at hand, only existing in the xml BLOB

    I also think that you could make your own javaclass and do the same thing, but I'm just not proficent in java as to who try here: P

  • Limit the number of CMIS query results

    Hello
    Can we limit the number of CMIS query results
    my query is
    SELECT * from ora: t:IDC:GlobalProfile WHERE the ora: p:xRegionDefinition AS \'ALERTRD\'
    I want only newer 2 alerts to display.

    Thank you

    You use the CMIS query in a workflow of presenter content in WebCenter Portal? These documents provide a maxResults parameter to set.

  • How to limit the length of the EditText control?

    All,

    How to limit the length of an EditText to accept ONLY 3 characters.

    The editText.characters property defines a size by default, but the user can always type more than 3 characters in the field.

    I got it!!!

    var win = new Window("dialog", "Limit 3");
    var txtLimit3 = win.add("edittext");
    txtLimit3.characters = 5;
    
    txtLimit3.onChanging = function (){
              howmany = txtLimit3.text;
              if (howmany.length > 3){
                        txtLimit3.text = "";
                        txtLimit3.textselection = howmany.slice(0,3)
                        }
              }
    
    txtLimit3.active = true;
    win.show();
    
  • How to limit the length of a text field in a dialog box (ADM)

    Hi all

    I need to limit the length of a field in a dialog box (ADM) edit_text, but char_limit doesn't seem to work, it's my code the problem ?

    {
    char_width: 8.
    height: 100,.
    item_id: 'Rete ',.
    type: 'edit_text. "
    Multiline: true,
    char_limit: 5.
    Width: 500,
    }

    If not, maybe I can use events to do the same thing with the onKeyStroke event but I don't know how to use the event in a dialog box (ADM) or if it is still possible...

    Any idea?

    Thank you for your help.

    Phil

    There are two events that can be used to check the length of the text,

    The first is the action event for the text field, which is called when the field loses focus, it is a member of the purpose of dialogue with the same name as the item_id.  This event could also be used to update another field in the dialog box that indicates the number of characters, you may even have a small picture of alert which becomes visible to make it obvious that there is a problem.

    The other event, as already mentioned, is the validate event.  This allows to block the exit from the dialog box and display a popup to alert to the user.

    You will find some examples of dialogs here:

    http://www.pdfscripting.com/public/65.cfm

    Take a look at the pages resize tool dialog box.  It will give you some ideas of what can be done.

    There is a plug-in Acrobat for creating dialogs here:

    http://www.windjack.com/products/AcroDialogs.html

    It's a Visual drag and drop Editor.  You can download and use for free for 10 days.

    Thom Parker
    The source for PDF Scripting Info
    pdfscripting.com

    The Acrobat JavaScript Reference, use it early and often
    http://www.Adobe.com/devnet/Acrobat/JavaScript.html

    Then more important JavaScript development tool in Acrobat
    The Console window (video tutorial)
    The Console Window (article)

  • Limit the length of the text to a fixed length

    I need to limit the length of a text fiield at some length to prevent packing. I can substr to a certain number of characters, but I use a proportional font (Arial), and the length of the string varies depending on the characters in the string.

    The field is the invoice number on a doc to check to RTF. If the field Bill encapsulates, it moves other objects on the control document and verify the cause of big problems printing.

    Is there a way to limit the length of a text field to an actual length printed on the document? Or prevent the area of packaging? IE just trunc it to a fixed length?

    Put the domain into a single table cell, select the table, right-click on it, choose Properties from the table in the menu, select the cell, click on the Options button, text Wrap option unceck.

  • Limit the search results with ", not".

    Is there a way to limit the search using the 'no '? For example, I searched for the industrial paper rolls and got pictures of toilet paper. I would have liked to find rolls of paper, excluding the toilet in the description of the image.

    Its possible using the sign less would help in that way it helps to google search.

  • Limit the number of characters in a text based on the first digit field

    Hello and thank you in advance for your help!

    I want to limit the amount of characters in the text field based on the first digit of the number (the text field is limited to a number format... no decimals, no comma).

    For example, if the number starts with a 3, I would limit the text field to allow only ten characters. I have three scenarios but if I could start with code and what is the best place to add (key combination or validation?) I can take it from there. Thanks again for your help!

    I wrote this code for you that does this. Use it as a typo of the custom field code:

    // Validate that only digits are entered
    if (event.change) {
        event.rc = /^\d+$/.test(event.change);
    }
    
    // Validate string length if it starts with 3
    if (/^3/.test(AFMergeChange(event))) {
        event.rc = AFMergeChange(event).length <= 10;
        if (!event.rc) app.alert("If the number starts with \"3\" it may not be longer than 10 digits.",1); // optional error message
    }
    

    You can duplicate the second part of it for additional terms, but keep in mind that this code won't let you even remove the first character in the field if the result is not valid.

    For example, if you enter "234567890123456" then you can't remove the "2" at the beginning because that would result in a number not valid. You can delete all the other numbers, even if and when it is 10 digits or less, then you can remove the departure "2" as well.

  • Limit the maximum number of characters per line in the TextField, help please

    Hello Livecycle designers!

    It would be great if you could help me with the following problem. I have a TextField with 5 lines (limit of the viewable area and the exact height) and I want to limit the maximum number of characters per line up to 10 (as well as the total in this field at 50, but I'm able to do with the option "time limit, max characters").

    As far as I know can be done only by the script so if you change that I wrote:

    lines of the var = xfa.event.newText.toString().split('\n');

    i = Lines.Length,
    maxChar = "10";

    If {(maxChar)
    While (I--> 0) {}
    If (rows [i] .length == maxChar) {}
    XFA. Event.change = "\n";
    }
    }
    }

    and actually who works very well when instead of '\n' in the 1st line, I put any character (e.g. ' |' and I won't pretend that ' |' is my new \n).

    So the main problem is to split the text entered by the user in lines (the '\n' is unfortunately not working). So the solution to this problem would somehow split my Textbox in lines (in table) after the user presses ENTER.

    I'd appreciate any help here, so if you have just 2 minutes of your time, please help me.

    Hello

    I have rebuild your idea... that is the result.

    var Input = xfa.event.fullText;

    var FullLength = Input.length;

    var SplitLength = 10

    var SplitParts = Math.ceil(FullLength / SplitLength)

    var JoinString = "";

     

    for (var i = 0; i)<= splitparts;="">

    {

    SplitString = Input.substring (0, SplitLength);

    Entry = Input.replace (SplitString, "");

    JoinString = JoinString + SplitString + "\u000a";

    }

    xfa.resolveNode("Textfield2").rawValue = JoinString;

  • How to limit the size of the decline shown down?

    Hello
    basically the starting
    I'm generating the drop down point SQL base LOV.
    one of the records is looooong.
    Is there a way to limit the length of the fall down, so it does not occupy 1/2 of the page?

    I have tried substr in LOV - it has not produced the desired result.

    Thank you.
    Andrew

    Andrew,

    It's weird... what version of Apex are you on?

    I made below in my apex.oracle.com work space and it seems to work fine...

    -Modify your agenda of the page selection list
    -In "HTML Form Element so" add style = "width: 500px;

    I tried it with 800px and 2px and both seem to work - tested in FF.

    You have nothing else in the properties of the item that might be it shaking?

    -Chris

  • How can I limit the number libraries which is to find Photos

    How can I limit the number libraries which is to find pictures?

    I have about 10 libraries I've migrated opening today.

    I followed the advice I got from leonie, (level 10) below.

    Photos will create a new library of Photos in your iPhoto library.  The new library will be named as the iPhoto, with the extension ".photoslibrary" library and your original library will have a new file name extension ".migratedphotolibrary".  Rename the resulting ".photolibrary", so you will always be able to open in Aperture. The icons of libraries will change also. New photo library will display an icon of 'fan photos' with the flower of the Rainbow.


    So, I have now two files in my folder "Images".   One is called "Photo library" (these are ALL of .photoslibrary) the other is 'BACKUP ONLY iPhoto libraries' (these are ALL of .photolibrary).

    When I hold down the option key and start the Photos is to find all the libraries of two files above. How can I say Photos don't not to look in the old folder "iPhoto library"?

    This isn't a feature of Photos

    You can request that Apple itself - http://www.apple.com/feedback/photos.html - but not, it is not an option

    LN

  • Limit the size and the content of string

    I was wondering if there is an easy way, predefined limit the number of characters, and what characters are allowed in a string.  I want to limit a string of 20 characters and does not allow for the apostrophe, comma, etc..  I'm sure I can this program, but thought it might already be something I could use?

    Asked several times in the past. Have you tried a search: http://forums.ni.com/t5/forums/searchpage/tab/message?location=Node%3A170&q=limit+string+length#mess...

  • Is it possible to limit the number of windows that can be opened?

    Original title: options in window 7

    I have an autistic son who likes to play on the internet (usually from sesame street, Barney and AFV videos on you tube).  The problem I have is that it will sometimes open many windows which eventually slows down the computer and results in me having to close the windows as well as his frustration.  Is it possible to limit the number of windows that can be opened?

    Hi Brian,.

    Thanks for posting your question in the Microsoft Community. It seems that you need more information to improve the performance of your computer.

    With the current configuration of Windows, there is no option to limit the number of windows that can be opened. You can search the 3rd application using your favorite search engine, which helps you to limit the number of windows that can be opened.

    Warning: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

    Link reference for more information.

    8.1 Windows, Windows 8 or Windows 7 crashes or freezes.

    http://support.Microsoft.com/kb/2681286/en-us

    Note: The data files that are infected must be cleaned only by removing the file completely, which means that there is a risk of data loss.

    I hope this helps. Please let us know if you need assistance.

Maybe you are looking for

  • Consultita...

    Hola! acabo comprarme una lenovo G485 y me gustaria saber cuanto tiempo seria recommended loading the Bateria por primera vez. Gracias

  • To add my HP Pav DV7-3160ED with a 2nd disc I need for a partnr for the 2nd drive bay with cable

    Hello Without hope of finding any of the HP Pavilion DV7-3160ED partnumbers. In this type of laptop, it is possible to mount a second disc of HD (SATA) or SSD. But that's why I need to order a second drive with cable Bay. But where to find that kind

  • Cannot restore to a restore point from the previous month.

    original title: my system restore won't let me restore to the previous month, the radio button works, but the habit of restoration my windows XP THAT behaves strangely and I tried to use the system restore which has worked well in the past, but now h

  • Problem with calendar blackBerry Smartphones - HELP

    Something screwed up in my calendar and I have all the entries in the so-called "telcel.blackberry.net" TRIPLICATED... I want to completely erase it and use only my Outlook calendar entries (or at least to have this update to Outlook so I got what I

  • NOT ABLE TO GET AUDIO IN WINDOWS 8

    Hey! until a few days ago, I was using windows 7 and I could hear the sounds... after that I installed windows 8 on my PC and then there was no sound at all... following one of the posts of this community, I installed updates and also tried to instal