Limit nbr of rows in a query

Dears,
I found 2 solutions to limit the number of rows a query can return:
- the first one is making use of a condition in the query itself based on RCOUNT
- a second one is setting the parameter ResultRowLimit in the instanceconfig file.
Now I was wondering how this works. Suppose that I want to limit my result set to the first 100 rows before retrieving the whole report.
Making use of the condition it's clear...an extra where-clause is added that will limit the number of rows retrieve.
But what with the ResultRowLimit parameter. Is the query retrieving all rows and only shows the first 100? Or is the execution of the query really restricted to the first 100 rows?
Can anyone explain me once?
Txs!!
PS if someone knows another solution to limit the query result, just let me know ;-)
Edited by: ADB on 6-jul-2009 8:07

Try using Analytic function row_number().
Regards
RK

Similar Messages

  • Limit no of rows in complex query

    Hi,
    I have below cursor query for which I need to limit no of rows retrieved to a certain value say 5000.
    I'm getting full table scan on table ltc_iss_rec if I do not specify a range
    for ltc_iss_rec.
    Thq query purpose get ref nos whose lc expiry date is less than or equal to
    sysdate -15.
    The max query below is also giving higher cost .
    Question si how to limit rows in cursor without using a range for ltc_iss_rec_id.
    The primary key in ltc_iss_rec is (ltc_iss_rec_id,psd_serial_num)
    Index in ltc_iss_rec is (ltc_iss_rec_id,lc_expr_dt)
    The primary key in psd is (psd_id,psd_serial_no)
    primary key in psd_link is (psd_id,psd_serial_no,link_psd_id,link_psd_ser_no)
    Index in psd_link is (link_psd_id,link_psd_ser_no)
    Index on psd_lcs is (update_serial_no)
    primary key on (psd_lcs) is (psd_id,psd_serial_no,other columns)
    SELECT MIN(ltc_iss_rec_id)
    INTO l_min_ltc_iss_rec_id
    FROM ltc_iss_rec
    WHERE lc_expr_dt <= ADD_MONTHS(SYSDATE,-15);
    SELECT MAX(ltc_iss_rec_id)
    INTO l_max_ltc_iss_rec_id
    FROM
    SELECT ltc_iss_rec_id
    FROM ltc_iss_rec
    WHERE ltc_iss_rec_id >= l_min_ltc_iss_rec_id
    ORDER BY ltc_iss_rec_id
    WHERE ROWNUM < l_iwh_arch_cnt;
    OPEN txn_ref_cur FOR
    SELECT b.ltc_iss_rec_id,b.psd_serial_num,a.sys_id,a.cosmos_ref_no,
    a.src_sys_asgn_ref_no,a.bank_id,b.lc_expr_dt
    FROM psd a,ltc_iss_rec b
    WHERE b.ltc_iss_rec_id >= l_min_ltc_iss_rec_id
    AND b.ltc_iss_rec_id <= l_max_ltc_iss_rec_id
    -- and b.lc_expr_dt <= add_months(sysdate,-15)
    AND a.psd_id = b.ltc_iss_rec_id
    AND a.psd_serial_no = b.psd_serial_num
    AND a.psd_typ_cod = 'ISS'
    AND a.psd_serial_no =
    SELECT NVL(MAX(link_psd_ser_no),'000') FROM psd_link c,psd_lcs d
    WHERE c.psd_id = d.psd_id
    AND c.psd_serial_no = d.psd_serial_num
    AND c.link_psd_id = a.psd_id
    AND c.link_psd_id BETWEEN l_min_ltc_iss_rec_id AND l_max_ltc_iss_rec_id
    AND d.update_serial_num = (
    SELECT MAX(f.update_serial_num) FROM psd_link e, psd_lcs f
    WHERE e.psd_id = f.psd_id
    AND e.psd_serial_no = f.psd_serial_num
    AND e.link_psd_id = a.psd_id
    ORDER BY b.ltc_iss_rec_id;

    Try using Analytic function row_number().
    Regards
    RK

  • Limit Number for Rows in BW Query Result

    Hello Experts,
        I am creating a query to be consumed by a web service. Therefore, I want to restrict the number of rows the query can display. Does anyone know a way to limit the result set to display only say FIRST 100 rows of data?
        I have looked at 'safety belt' solution, i.e. limiting number of cells to for example, 5000 cells. However, when the limit is exceeded the query just shows an error message not the first 5000 cells.
    thanks,
    Kartik

    Hi,
    You can do some things like..........
    Do not display the data in a detailed level.
    Use Always Suppress option in the result set.
    Also it depends on your Query definition. If your rows contains Branch wise or Region Wise, then your report will be fit in your first level of output. You need not to drilldown further.
    Why do you want to consider only first 1000 rows if you are planning to use it by Web service?
    I don't know whether it is feasible or not. I have one more alternative for you. You can try to achieve by APD by the Query. Insert a ABAP routine which should consider first 1000 result rows for your Web service. Just throw a light on this idea..............
    Regards,
    Suman

  • How do you limit the number of rows return from query?

    How do you limit the number of rows return from query? Do all databases support this kind of feature?

    i think the standard is limit
    to get the top 30
    select * from mytable LIMIT 30;returns the first 30 rows
    also if you want a range
    select * from mytable LIMIT 10,30;returns 30 rows starting from 10
    this last one is useful for displaying ranges... something similar happens in these forums when viewing topics and messages

  • Limit number of rows from wildcard expansion- DRG-51030

    We use CONTEXT iindex in 11g to search on a text DB column, "Name".
    This is used in a UI to show autosuggest list of 25 matching names.
    When the end user types an 'a' we want to show a list of the first 25 names that contain an 'a'.
    We hit the issue of too many matches in the wildcard expansion query:
    DRG-51030: wildcard query expansion resulted in too many terms
    This is a frequent use case when the user types just 1 character ('a' will easily match over 50K names in our case).
    Is there a way to make the wildcard expansion query only return the first 25 rows?
    We never show more than 25 names in our UI - so we would like the expansion query to also return max of 25 rows.
    Our query is:
    SELECT ResEO.DISPLAY_NAME,
    ResEO.RESOURCE_ID,
    ResEO.EMAIL
    FROM RESOURCE_VL ResEO
    WHERE CONTAINS (ResEO.DISPLAY_NAME , '%' || :BindName || '%' )>0
    Also,
    Is there a way to use CTXCAT type of index and achieve this (expansion query limit of 25)?
    We are considering switching to CTXCAT index based on documentation that recommends this type of an index for better performance.

    Your best bet may be to look up the words directly in the $I token table.
    If your index is called NAME_INDEX you could do:
    select /* FIRST_ROWS(25) */ token_text from
      (  select token_text
         from dr$name_index$i  
         where token_text like 'A%' )
    where rownum < 26;That should be pretty quick.
    However, if you really want to do %A% - any word which has an A in it - it's not going to be so good, because this will prevent the index being used on the $I table - so it's going to do a full table scan. In this case you really need to think a bit harder about what you're trying to achieve and why. Does it really make any sense to return 25 names which happen to have an A in them? Why not wait until the user has typed a few more characters - 3 perhaps? Or use my technique for one or two letters, then switch over to yours at three characters (or more).
    A couple of notes:
    - Officially, accessing the $I table is not supported, in that it could change in some future version, though it's pretty unlikely.
    - I trust you're using the SUBSTRING_INDEX option if you're doing double truncated searches - a wild card at the beginning and end. If not, your performance is going to be pretty poor.

  • How can I do for a row of a query be data provider for a variable?

    Hi friends, I have a problem !
    How can I do for a row of a query be data provider for a variable?
    I need that a value of variable be stored when the user select a row in a query. At the BPS we can do this configuring the variable selector in WIB, and in a WAB how I can do this ?
    Best regards,
    Gustavo Liberado

    In this case when I press the key to call other forms I need to wait for the response in the secondary form and then process the result.That is exactly what a "modal JDialog" (or JOptionPane) are used for.
    Try it. Create a short demo program. All you need is a JFrame with a single button to show the modal dialog. All you modal dialog needs is a single button to close the dialog. After you show the modal dialog add a System.out.println(...) statement in your code and you will see that it is not executed until the dialog is closed.
    Then once you understand the basics you add the code to your real program.
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

  • Can I use SYSDATE in the WHERE clause to limit the date range of a query

    Hi,
    Basicaly the subject title(Can I use SYSDATE in the WHERE clause to limit the date range of a query) is my question.
    Is this possible and if it is how can I use it. Do I need to join the table to DUAL?
    Thanks in advance.
    Stelios

    As previous poster said, no data is null value, no value. If you want something, you have nvl function to replace null value by an other more significative value in your query.<br>
    <br>
    Nicolas.

  • Finding minimum value in each row using dynamic query

    need to find the minimum and maximum value from each row using dynamic query
    [from curr] will be given as input
    Tuky

    DECLARE @t TABLE(a INT,b INT,c INT);
    INSERT @t VALUES(1,2,3),(9,8,7),(4,6,5);
    SELECT *
    ,      (   SELECT  MAX(val) 
               FROM    (VALUES (a)
                           ,   (b)
                           ,   (c)
                       ) AS value(val)
           ) AS MaxVal 
    ,      (   SELECT  MIN(val) 
               FROM    (VALUES (a)
                           ,   (b)
                           ,   (c)
                       ) AS value(val)
           ) AS MinVal 
    FROM @t;
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Limit Number of Rows on a Page

    Hi all,
    I am unable to succeed with the following.
    I have an XML data source which looks like this:
    <?xml version="1.0"?>
    <LIST_GEMPLOYEES>
    <LIST_G_EMPLOYEE>
    <EMPLOYEE_NUMBER>1</EMPLOYEE_NUMBER>
    <EMPLOYEE_NAME>Employee 1</EMPLOYEE_NAME>
    </LIST_G_EMPLOYEE>
    <LIST_G_EMPLOYEE>
    <EMPLOYEE_NUMBER>2</EMPLOYEE_NUMBER>
    <EMPLOYEE_NAME>Employee 2</EMPLOYEE_NAME>
    </LIST_G_EMPLOYEE>
    <!-- many rows here (LIST_G_EMPLOYEE tags) -->
    </LIST_GEMPLOYEES>
    And I want to define a template which only allows 5 rows on a page.
    What I did:
    I should insert a page break after the limit number of rows on a page is reached. This means that, after each group of 5 rows, a page break should be inserted.
    To accomplish this goal, I followed these steps:
    1. Define a field which will contain and initialize the Counter variable before the table which will show the list of employees, by using the syntax:
    Field1: <?xdoxslt:set_variable($_XDOCTX, ’Counter’, 0)?>
    2. Define the table which list all employees in the data source:
    2.1. Use a 2 columns table. In the first column, define 2 fields as follows:
    2.2. In the second column, define 6 fields containing the following code:
    Field2: <?for-each: LIST_G_EMPLOYEE?>
    Field3: <?EMPLOYEE_NUMBER?>
    Field4: <?xdoxslt:set_variable($_XDOCTX, ’Counter’, xdoxslt: get_variable($_XDOCTX, ’Counter’) + 1)?>
    Field5: <?EMPLOYEE_NAME?>
    Field6: <?if: xdoxslt:get_variable($_XDOCTX, ’Counter’) mod 5=0?>
    Field7: <?split-by-page-break:?>
    Field8: <?end if?>
    Field9: <?end for-each?>
    Here is explanation for syntax I used:
    Field1: Declare and init Counter variable to value = 0
    Field2: This fetches through all employees - start a for-each cycle
    Field3: This prints the employee number
    Field4: This increments the Counter variable
    Field5: This prints the employee name
    Field6: This tests whether Counter variable is divided by 5
    Field7: This generates a page break
    Field8: End of condition
    Field9: End of for-each cycle
    Result:
    The first page has just the header and the second page has the header and only record and it goes the same
    for the rest of the pages. Any help is greatly appreciated.
    Thanks.

    Have a look at this post
    http://winrichman.blogspot.com/2008/09/limit-row-per-page.html

  • Result Rows in a Query

    Hi
    I have sales org, channel, customer and material along with the key figures in the rows
    of the query. I am automatically getting result for each level by default and then the
    overall result. Is there a way in which i can change all the result rows with
    the corresponding text they belong to like the material result, customer result etc.
    Thanks
    Rashmi.

    Hi
    Not Sure, But try replacement path Variable (with Material Result...etc) and the ckf/Formula(total all the Material, channel...etc) for the same to appear the totals Row .
    /people/kamaljeet.kharbanda/blog/2006/12/28/bex-characteristic-variable-with-replacement-path
    Hope it helps and clear

  • Result Row in the query output

    Hi,
    If I restrict a characteristic by hierarchy then I can’t have the result row displayed. If the hierarchy active is removed then the result row gets displayed. All characteristics are marked to show the result row.
    This characteristic is Account Number. If in the query definition I remove the restriction on account numbers and just select hierarchy active and the required hierarchy in the properties then I get the result row in the output. But now it also displays all the unassigned account numbers in a separate node “Not Assigned Account Number (s)”.
    I can’t even restrict it in the output with hierarchy active selected. When I do select filter value in the output the options Include in Selection and exclude from Selection are grayed out and hence can’t select it.
    Please advice on this issue…
    Thank you,
    sam

    Hi Jaya,
    I think you misunderstood my issue.
    My problem is not that i do not want to see the field. But instead, i do not want to see only the results row in the query output.
    I need to have the results to populate a calculation via sumct formula.
    My question is, can sumct be populated if i hide/supress RESULT row ?
    Regards,
    Maili

  • Updating, Adding, or Deleting rows from a query

    So, I've got this page that originally was made of four
    different forms. It worked great. But, then the client asked that I
    "idiot proof" the page.
    Originally, I had a form that enclosed a one-line table (with
    Add & Clear buttons on the end) that took seven fields and
    "added" a new record to the "tbljob" table.
    That was followed with another form that created a table from
    the results of a cfquery and listed all the rows from tbljob (with
    Update/Delete buttons on the end of each row).
    This worked fine when it was two separate forms. Now, I'm
    trying to use only one "form" while displaying the two tables. The
    buttons are now done with Javascript (so there are dialog boxes).
    The problem is that I am getting a CF error message because the
    insert, update, and delete commands are trying to pass the contents
    of the fields as comma-delimited lists rather than the single data
    item that is actually in each field. I am passing a hidden field
    with each row that contains the "job_id".
    I know the problem is that I'm not identifying each row as
    being unique. I guess it's like I'm passing an "array" of data
    rather than just a "row".
    Basically, I just want to be able to display a blank row for
    adding records followed by multiple rows from a query. The blank
    row needs to have "Add" and "Cancel" buttons at the end and the
    multi-row part has to have "Update" and "Delete" buttons on the end
    of each row and manage the appropriate records.
    It's got me stumped. TIA.

    What you can do is try using <cfloop> to insert, update
    and delete your information.
    For instance deleting the information try this.
    <!---- Delete Jobs---->
    <cfloop index="JobIDs" list="#Job_ID#" delimiters=",">
    <cfquery name="delteall" datasource="dbsource">
    DELETE
    FROM table
    Where job_Id = #JobIDs#
    </cfquery>
    </cfloop>
    Do the same for your inserting and updating.
    Because what CF see is job_id = 1,2,3,4,5,6,7,8,9
    SO you are looping over a list = #job_id# and delimiter is "
    , " and we are calling the index JobIDs. JobIDs are the values - 1
    2 3 4 5 6 ....
    I hope this helps. As for the displaying of the images, use
    if then statements:
    <cfif isdefined("edittable") and edittable eq '"y">
    Then display the query and outputs for the editing options
    <cfelseif isdefined("deletetable") and addtable eq "y">
    The dispaly the query and outputs for adding options
    <cfelse>
    Then display the query for outputing the delete options
    </cfif>
    So your link will have soemthing of this sort <a
    href="samepage.cfm?deletetable=y">Add Table</a>
    Hope this helps,
    Sevor Klu

  • Change of Row Property during query execution possible?

    Hello Experts,
    is it possible to change the row property during query execution?
    In the case an input ready IP query can be executed for different customers. Depending on the customer class (attribute of customer), a certain row (containing account data) should be input ready or only be shown, but not input ready.
    How can this be achieved?
    Thank you!
    Angie

    Hi Angie,
      To determine the input readiness at  Run time based on the master data value of a particular characteristic value (In your case Customer),
    you can create data slice of type exit .
    The data slice is based on an exit class. In the exit class, you can implement a customer-specific logic to protect data records.
    Please refer to http://help.sap.com/saphelp_nw2004s/helpdata/en/43/0c033316cd2bc4e10000000a114cbd/frameset.htm
    for more information.
    By using this, the required rows will be shown but not input ready ( As per your requirement)
    Hope this info helps. Or do let us know !!
    Best regards,
    Akshata

  • Grouping rows from a query

    Hi everyone!
    I want to know if it's posible to group the rows from a query into a unique row. Example:
    SELECT Field_1 FROM Table_1
    Returns the following fileds:
    Field_1
    A
    B
    C
    D
    I would want to modify my query so that the result obtained would be a single row containing all the others. In the previous example the result would be "ABCD".
    Thanks in advance. Best regards,

    -- For anyone who wants to test this,
    -- just copy this entire post as is,
    -- save it to a .sql file, then start that file.
    -- Before doing this,
    -- make sure that you don't already have
    -- a table named table_1 that would be dropped
    -- or a .sql file named query.sql that would be overwritten.
    -- If you do, then change the names below to avoid any conflicts.
    -- In order to understand what the code is doing,
    -- please read all of the comments included in this file,
    -- as not everything is displayed when you run it.
    -- I have gone into great detail with this
    -- because I have posted similar things before
    -- and a lot of people have total missed the fact
    -- that it is not a static query,
    -- that the results are dependent upon the number of rows,
    -- and that it works for any number of rows,
    -- even when the number of rows is unknonwn.
    -- test data:
    DROP TABLE table_1
    CREATE TABLE table_1
      (field_1 VARCHAR2 (1))
    INSERT INTO table_1 (field_1)
    VALUES ('A')
    INSERT INTO table_1 (field_1)
    VALUES ('B')
    INSERT INTO table_1 (field_1)
    VALUES ('C')
    INSERT INTO table_1 (field_1)
    VALUES ('D')
    COMMIT
    SELECT * FROM table_1
    -- Running the code below will create and start
    -- a file named query.sql which will contain the query below,
    -- which will produce the results below that:
    -- query that will be created:
    -- SELECT MAX(DECODE(ROWNUM,1,field_1,NULL))                                      
    -- ||MAX(DECODE(ROWNUM,2,field_1,NULL))                                           
    -- ||MAX(DECODE(ROWNUM,3,field_1,NULL))                                           
    -- ||MAX(DECODE(ROWNUM,4,field_1,NULL))                                           
    -- FROM table_1 GROUP BY NULL;                                                    
    -- results that will be produced:
    -- ABCD
    -- Notice that in this example,
    -- there are only four values concatenated
    -- because there are only four rows in the table. 
    -- If there were more rows, it would concatenate more values. 
    -- The number of concatenated values
    -- is dependent upon the number of rows.
    -- The following dynamic sql uses a single query,
    -- which produces and executes a single query,
    -- whose number of concatenated values is dependent
    -- upon the number of rows in the table.
    -- Because the echo is set off in the first line,
    -- you won't see this code when you run it,
    -- just the query that it creates.
    SET     ECHO OFF FEEDBACK OFF HEADING OFF PAGESIZE 0 VERIFY OFF
    SPOOL   query.sql
    -- This is the start of the single query:
    SELECT  text
    FROM    (SELECT 1                                             AS orderby,
                    'SELECT MAX(DECODE(ROWNUM,1,field_1,NULL))'   AS text
             FROM   DUAL
             UNION
             -- This section is the part that dynamically creates
             -- one additional concatenated value
             -- for each additional row after the first row.
             -- This is just a subquery within the single query.
             SELECT rn                                            AS orderby,
                    '||MAX(DECODE(ROWNUM,'||rn||',field_1,NULL))' AS text
             FROM   (SELECT ROWNUM rn
                     FROM   table_1)
             WHERE  rn > 1
             UNION
             SELECT COUNT (*) + 1                                  AS orderby,
                    'FROM table_1 GROUP BY NULL;'                  AS text
             FROM   table_1)
    ORDER BY orderby;
    -- This is the end of the single query.
    SPOOL    OFF
    START    query
    SET      ECHO ON
    -- If you want to see the file containing
    -- the single query that was created, then just:
    -- SQL> EDIT query.sql

  • Single row from this query without create a group by

    Can I have a single row from this query without create a group by on tipo (TIPO can have only 2 value (A,D)
    SELECT
    CASE TIPO
    WHEN 'D' THEN SUM(IMPORTO) ELSE 0 END DIMPORTO,
    CASE TIPO
    WHEN 'A' THEN SUM(IMPORTO) ELSE 0 END AIMPORTO
    FROM MGIORNALE
    WHERE K_CONTO = '100001' --CONTO
    AND DECODE(T_MOVIM,'MRAP',TO_DATE('31/12/'||to_char(a_competenza),'DD/MM/YYYY'),DATA_RG)
    -- BETWEEN DATAA AND DATAB
    BETWEEN '01/01/2006' AND '31/12/2006'
    --GROUP BY TIPO
    --AND TIPO = COL_conto
    Thanks in advance

    Is like this?
    sum (CASE TIPO
    WHEN 'D' THEN IMPORTO ELSE 0 END) DIMPORTO,

Maybe you are looking for

  • Problem in Script Perform

    Hi, I have to add 3 values for this i have written a perform in text element of main window as follows. /: DEFINE &DO_TOT& := '0'. /: PERFORM DO_TOTAL IN PROGRAM Z_1IEXCP_OUTPUT /: USING &J_1IEXCHDR-EXBED& /: USING &J_1IEXCHDR-ECS& /: USING &J_1IEXCH

  • How can I make an XML file print �, � and �

    When I write an xml file by hand I can use the European alphabet and the letters �,� and �. I can also write to an ordinary text file from my Java code and still be able to display the letters as they should. But when writing to an xml file in my Jav

  • Hiring Someone to Create a Customized Aperture Web Journal Template

    I'm interested in creating a customized Web Journal template for Aperture. Does anyone know anybody out there I could hire to do such a project?

  • Adding a Old PC hard disk drive as a external drive to my MBP

    So around 5 years ago i got the WD-160JB hard disk drive. I want to see all the things i did back then. I want to be able to connect this WD-160JB drive as a external hard drive to my mac. What i am wondering is if you can somehow have a cable or som

  • Cluster changing hostname & Logical host

    hello I have sunCluster 3.1 update 4. the cluster is 2(v440) + 1(v240) installed on solaris8. Did anyone actualy succeeded to change the hostnames of all the nodes & Logical host on SunCluster system like above? I saw a procedure that is not realy su