Fitching a specific number of rows

hi all
i want to fitch a specific number of rows in my query
not all matches (SQL2000 Server )
what command in my sql query can be placed to do so
thanks

set rowcount n

Similar Messages

  • Select  a specific  number of rows in query

    How can a specific number of rows be selected in a query? For example, a query retrieves 30,000 records and I want to retrieve the output by groups of 5,000. I want the query to retrieve the first 5,000 records, then the next 5,000 records etc. I tried rownum but that does not work.
    Thanks,
    PANY

    Not AGAIN. Please...........
    Do you know how to Google? Search forum?
    Why do you ask this boring FAQ AGAIN?
    Sybrand Bakker
    Senior Oracle DBA
    Experts: Those who know how to search.

  • Getting a specific number of rows

    Hi,
    I would like to know how to get a specific number of rows. For example, I want to page data in my web application, so I'd like to be able to retrieve just 25 rows in my SELECT statement. I searched and I couldn't see anything under the obvious keywords of LIMIT and TOP (as used by other database vendors) so I'm wondering if possible, what do I need to do - a pointer to the relevant documentation would be helpful also.

    You can achieve this with rownum
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns009.htm#i1006297
    Best regards
    Maxim

  • Return specific number of rows depending on the data in a column in table

    Hi,
    I have a table named orders which has column orderid and noofbookstoorder in addition to other columns.
    I want to query the orders table and depending on the value of the 'noofbookstoorder' value return that number of rows.
    Eg
    Orderid noofbookstoorder
    1 1
    2 3
    3 2
    when I query the above data saying
    select * from orders where orderid=2;
    since it has noofbookstoorders value as 3 the query should return 3 rows and when I query
    select * from orders where orderid=3;
    it should return 2 rows and
    select * from orders where orderid=1;
    should return 1 row.
    Is it possible to achieve this. If yes, then how do I write my query.
    Thanks in advance.

    with t as (
               select 1 Orderid,1 noofbookstoorder from dual union all
               select 2,3 from dual union all
               select 3,2 from dual
    select  t.*
      from  t,
            table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
      where Orderid = <order-id>
    /For example:
    SQL> with t as (
      2             select 1 Orderid,1 noofbookstoorder from dual union all
      3             select 2,3 from dual union all
      4             select 3,2 from dual
      5            )
      6  select  t.*
      7    from  t,
      8          table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
      9    where Orderid = 2
    10  /
       ORDERID NOOFBOOKSTOORDER
             2                3
             2                3
             2                3
    SQL> with t as (
      2             select 1 Orderid,1 noofbookstoorder from dual union all
      3             select 2,3 from dual union all
      4             select 3,2 from dual
      5            )
      6  select  t.*
      7    from  t,
      8          table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
      9    where Orderid = 3
    10  /
       ORDERID NOOFBOOKSTOORDER
             3                2
             3                2
    SQL> with t as (
      2             select 1 Orderid,1 noofbookstoorder from dual union all
      3             select 2,3 from dual union all
      4             select 3,2 from dual
      5            )
      6  select  t.*
      7    from  t,
      8          table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc
    iNumberList))
      9    where Orderid = 1
    10  /
       ORDERID NOOFBOOKSTOORDER
             1                1
    SQL>  -- And if you want to select multiple orders
    SQL> with t as (
      2             select 1 Orderid,1 noofbookstoorder from dual union all
      3             select 2,3 from dual union all
      4             select 3,2 from dual
      5            )
      6  select  t.*
      7    from  t,
      8          table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc
    iNumberList))
      9    where Orderid in (2,3)
    10  /
       ORDERID NOOFBOOKSTOORDER
             2                3
             2                3
             2                3
             3                2
             3                2
    SQL> SY.
    Edited by: Solomon Yakobson on Oct 26, 2009 7:36 AM

  • Select specific number of rows

    i'm listing all data entries in a database.
    for that i want to select the 1st ten entires, then the next ten and so on ordered
    by date_column.
    how can i do that? is it possible with rownum?
    in mysql/php i did it with limit
    $query = "select * from article where parent_id=0 order by date desc, time desc limit $select, 10";
    please email me.
    thanks for help
    chris

    but what about rownum if i want the
    records from 10-20?
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Chen Zhao ([email protected]):
    If you are using Oracle 8i, you can use ROWNUM to specify the specific number of records. You can see the ROWNUM by querying:
    SELECT *
    FROM (SELECT column_name FROM table_name ORDER BY column_name)
    WHERE ROWNUM<10
    CHEN<HR></BLOCKQUOTE>
    null

  • Specific number of rows within field(s)

    I'd like to get Top-N of Amt within Name&Loc as shown below.
    Is there a way to reset either COUNT or ROWNUM to get this result?
    Name---Loc--(ROWNUM)--Amt
    James--abc--------1--1000
    James--abc--------2---900
    James--abc--------3---750
    James--def--------1---500
    James--def--------2---300
    Jill---abc--------1---400
    Jill---abc--------2---150
    Jack---xyz--------1--2000
    Jack---xyz--------2--1800
    Thank you in advance for your help.

    try this,
    select rownum as rank,ename,sal from ( select ename,sal from emp order by sal desc) where rownum<6
    This query works on EMP table of SCOTT user.
    If you change "desc" to "asc" it will start from lower to higher values. You can also play with the condition ( rownum < 6 ) to fetch ur desired no. of rows.
    Hope this helps,
    Kalpen.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Danielle:
    Thanks for the reply, but that's not what I'm looking for.
    Is there a way to get the Top-N (top 10,top20...)records within a group of fields (e.g. Name & Loc )?<HR></BLOCKQUOTE>
    null

  • Setting a specific number of rows visiable in a JTable

    Hi there,
    I am implementing the Master-Detail pattern by using a using a JSplitPane to devide a JPanel into two.
    In the upper split-pane I show a JTable as the Master View.
    In the lower split-pane I show a JTable as the Detail View.
    My problem is that I just want to show 2 (two) rows and the Header in the Detail-View.
    The default behavier is that my SplitPane shows 1 and a half row and the tableHeader.
    How can I tell the SplitPane that I (only) want two rows and the Header ?

    table.setPreferredSize(...);Hi again,
    thanks for input !
    I tried your suggestion but it did not help me.
        int rowHeight = detailCompareTable.getRowHeight();       
        Dimension headerSize = detailCompareTable.getTableHeader().getPreferredSize();       
        d = new Dimension ((int) d.getWidth(), (int) (2 * rowHeight + headerSize.getHeight()));
        detailCompareTable.setPreferredSize(d);
       masterDetailSplitPane.resetToPreferredSizes();What am I gettig wrong ?

  • JTextArea - set specific amount of rows, or characters...

    I'm working on a Applet which handles text according to given parameters. One of these parameters sets a JTextArea to the horizontal size of, lets say: 5 rows. What i want is that once this TextArea is set to a specific number of rows no text beyond those rows can be inserted. 5 rows, or a specific amount of characters are allowed.
    My problem is that the TextArea wont stop allowing text vertically. The TextArea is visibly set to 5 rows, which doesnt change. But how can i stop text from being inserted beyond row 5?
    We have tried a number of different approaches, from trying to set TextArea's size with invisible scrollbars to overriding invalidate()...

    I never understand why people want to limit the number of rows in a JTextArea. Add the text area to a scroll pane and scroll bars will appear when the number of rows exceed the display area. The point of using a text area is to allow the user to enter data in a flexible format. If the format is not flexible then maybe you should be using another component or combination of combination of components.
    Setting a maximum character size is valid if you intend to store the data on a database with a fixed size field. It is easy to do this by using a custom Document with you JTextArea. Read this section from the Swing tutorial on "General Rules for Using Text Components" for example code on how to do this:
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html
    Note, if you really want to limit the text area to 5 lines then count the number of new line characters in the document and don't allow them to enter more than 4.

  • How to limit the number of rows in a report

    I have several reports with a number of parameters - date ranges etc.
    Depending on the parameter values selected by the user the reports can return thousands of rows.
    I would like to limit the number of rows returned to, say, 500. If more than 500 rows are returned by the query then display an error message requesting that the user enter more specific parameters.
    Ideally for performance reasons it would be good to catch the error before the datafile is generated, but I don't know if this is possible. Alternatively a check in the template might do the job - using COUNT on the group?.

    Hi Hugh,
    In your query, you got to add rowum < 500 or some sort of DB specific limit to the row being returned,
    this will help to stop the report to get more than 500 records and the report template wont have any restriction.
    or
    you can do that in template too, but i would not recommend.
    In these both cases or in any case, you cannot give any meaningful error if it exceeds N rows,there is no option like this till now.

  • Different number of rows for different columns in JTable

    hi
    I need to create a JTable with different number of rows for different columns...
    Also the rowheight should be different in each column...
    say there is a JTable with 2 columns... Col1 having 5 rows and column 2 having 2 rows...
    The rowHeight in Col2 should be an integer multiple of Rowheight in Col1
    how do I do this ??
    can anybody send me some sample code ?????
    thanx in advance

    How about nesting JTables with 1 row and many columns in a JTable with 1 column and many rows.
    Or you could leave the extra columns null/blank.
    You could use a GridBagLayout and put a panel in each group of cells and not use JTable at all.
    It would help if you were more specific about how you wanted it to appear and behave.

  • How to Efficiently Sample a Fixed Number of Rows

    Good afternoon. I need to select a specific number of random rows from a table, and while I believe my logic is right it's taking too long, 30 minutes for a routine data size. Hopefully someone here can show me a more efficient query. I've seen the SAMPLE function, but it just randomly selects rows on a one-by-one basis, without a guaranteed total count.
    This is the idea:
    INSERT INTO Tmp_Table (Value, Sequence) SELECT Value FROM Perm_Table, DBMS_RANDOM.VALUE;
    SELECT Value FROM Tmp_Table WHERE ROWNUM <= 1234 ORDER BY Sequence;I'd need to put the ORDER BY in a subselect for ROWNUM to work correctly, but anyway that's just an illustration. My actual need is a little more complicated. I have many sets of data; each set has many rows; and for each set I need to return a specific (different) number of rows. Perhaps project A has three rows in this table, and I want to keep two of them; project B has two rows, and I want to keep one of them. So I need to identify, for each row, whether it's valid for that project. This is what my data looks like:
    Project Person  Sequence Position Keeper
    A       Bill    1234     1        Yes
    A       Fred    5678     3        No
    A       George  1927     2        Yes
    B       April   5784     2        No
    B       Janice  2691     1        YesI populate Sequence with random values, then calculate the position of each person within their project, and finally discard people who's Position is greater than Max_Targets for the Project. Fred and April have the highest random numbers, so they're cut. It's not the case that I'm just trimming one person from each project; the actual percentage kept will range from zero to 100.
    Populating the list with random values is not time-consuming, but calculating Position is. This is my code:
    UPDATE Tmp_Targets T1
    SET Position =
      SELECT
       COUNT(*)
      FROM
       Perm_Targets PT1
       INNER JOIN Perm_Targets PT2 ON PT1.Project = PT2.Project
       INNER JOIN Tmp_Targets T2 ON PT2.Target = T2.Target
      WHERE
           T1.Target = PT1.Target
       AND T2.Sequence <= T1.Sequence
      );The Target fields are PKs, and the Project and Sequence fields are indexed. Is there a better way to approach this? I could write a cursor that pulls out project codes and performs the above operations for each project in turn; that would be logically simpler and possibly faster. Has anyone here addressed a similar problem before? I'd appreciate any ideas.
    This is on 9.2, in case it matters. Thank you,
    Jonathan

    You've not given any indication of how max targets for a given project is determined, so for my example I'm using the ceiling of 1/2 of the number of records in each project which gives the same number of yes and no responses per project as you had:
    with dta as (
      select 'A' project, 'Bill' person from dual union all
      select 'A', 'Fred' from dual union all
      select 'A', 'George' from dual union all
      select 'B', 'April' from dual union all
      select 'B', 'Janice' from dual
    ), t1 as (
      select project
           , person
           , row_number() over (partition by project order by dbms_random.value) ord
           , count(*) over (partition by project) cnt
           , rownum rn
        from dta
    select project
         , person
         , ord
         , cnt
         , case when ord <= ceil(cnt/2) then 'Yes' else 'No' end keep
      from t1
      order by rn
    PROJECT PERSON ORD                    CNT                    KEEP
    A       Bill   2                      3                      Yes 
    A       Fred   3                      3                      No  
    A       George 1                      3                      Yes 
    B       April  1                      2                      Yes 
    B       Janice 2                      2                      No  
    5 rows selectedIn this example I use an analytic function to assign a random ordering for each record within a project in the middle query, in the final output query I am determining the yes no status based on the order within a project and the count of records in the project. If you had a table of projects indicating the thresh hold you could join to that and use the thresh hold in place of the ceil(cnt/2) portion of my inequality in the case statement.

  • ORA-01422 exact fetch returns more than requested number of rows on invoice

    Hello developer,
    Current I m facing problem ORA-01422 exact fetch returns more than requested number of rows in Invoce Standard form when we select PO_Default invoice type for some specific PO Number not for all. I m not able to handle the error bcoz im new in oracle apps. it's urgent for user requirement. Plz guide me how to take approch to handle the situation.........
    select Po_Default invoice type=>enter po number=>press ok button=>got error ORA-01422
    I got query from POST_QUERY TRIGEER like
    function get_po_number (l_po_number varchar2,l_vendor_id OUT number) return number is
    l_po_header_id number;
    --Bug fix:1096002
    --Removed the function call UPPER from the WHERE clause so that the query
    --becomes case sensitive.
    -- BUG 2519682 vendor_id added in the Select statement and futher in the fetch statement
    cursor po_number_cursor is
    SELECT po_header_id,vendor_id
    FROM po_headers
    WHERE type_lookup_code IN ('STANDARD', 'BLANKET', 'PLANNED')
    AND approved_flag = 'Y'
    AND segment1 = l_po_number
    -- Bug 2289727. Enhanced Matching Controls to Finally Closed POs
    AND (NVL(closed_code, 'X') <> 'FINALLY CLOSED'
    OR :parameter.show_final_closed_po_flag = 'Y')
    AND PCARD_ID IS NULL; --bug4627502
    /* Commented out since this is not relevant even if executed.
    AND (segment1 LIKE SUBSTR(l_po_number, 1, 2) || '%' OR
    segment1 LIKE SUBSTR(l_po_number, 1, 1) ||
    SUBSTR(l_po_number, 2, 1) || '%' OR
    segment1 LIKE SUBSTR(l_po_number, 1, 1) ||
    SUBSTR(l_po_number, 2, 1) || '%' OR
    segment1 LIKE SUBSTR(l_po_number, 1, 2) || '%' );
    begin
    open po_number_cursor;
    fetch po_number_cursor INTO l_po_header_id,l_vendor_id;
    close po_number_cursor;
    return(l_po_header_id);
    end get_po_number;
    plz help me how to resolved this issue it's urgent.
    thanks in advance.........

    This bug is documented in the following note on metalink.oracle.com
    APXINWKB - Creating PO Default Invoice Errors with ORA-01422 Exact Fetch Returns More Than Requested Number Of Rows [ID 946578.1]
    The solution is to apply patch 8765847.
    Hope this answers your question,
    Sandeep Gandhi

  • Number of Rows in a Tree

    I think this should have a fairly simple answer, but I can't find it for the life of me. Is there somehow I can obtain the total number of rows in a tree control? With a listbox you can use the Property node "ItemNames" and just use an Array Size, but Tree Controls don't seem to have anything similair. Any ideas? Am I missing something simple?
    Michael

    Hi miguelc,
    If nothing else miguel, this forum specifically answered how to get tree structure sizes.  Happy programming.
    Brian K.

  • How can I get a fixed number of rows on a SELECT?

    I'm interested on get the last xx records of one specific query that returns an higher number of rows than xx. How can I do this?

    you can use "where rownum < xx" if you
    write "select * from (select ... from ... order by ...) where rownum < 10"
    but you can't write "rownum > 10" because no record will be returned.
    therefor you have to do like this:
    select * from (select ..., rownum as nummer from (select ... from ... order by ...)) where nummer > 10
    ~
    pascal

  • Need to limit number of rows returned by a query

    Hi. Is there a way to limit the rowsets returned to me in a query? I need to get the first 100, then the next hundred, etc until there are no more rows left to retrieve. Someone told me that I should use a cursor to do this. Does anyone have a specific example? Can this be done with a combination of SQL/JDBC?
    Thanks in advance...bbetta
    null

    if you are talking about limiting the number of rows to be returned to the calling program to a managable number of rowa ...
    for example the result set size would be 5000 rows and you want to get them in batches of 50 or 100 ..
    see the attached link :
    JDBC Code Templates
    http://technet.oracle.com/sample_code/tech/java/sqlj_jdbc/htdocs/templates.htm#BatchSize
    if you want the server side transaction to only return the first 50 or 100 rows even though the result set has more ... then
    another approach is required -- possibly as suggested above ...

Maybe you are looking for

  • Task working in foreground, not working in background

    Hi Experts, I am facing one strange problem. I have created one Z BOR where i have written one method to fetch data from database. I have added one task in workflow which calls this method. When the task runs in foreground its perfectly fetches data.

  • Need Help with Uploading IPA to AppStore

    Having some troubles uploading my completed IPA to the appstore. 1) Using Flash Professional CC 2) Built with Air 3.8 for iOS 3) Uploading it via Application Loader 4) Encountered the following errors:      >> Apple's web service operation was not su

  • Synchronous HTTP Response

    Hello, In our process we receive a cXML document via http which creates a SO in our R/3 system. According to the cXML specification we need to send a response xml back to the trade partner. This response needs to specify if the xml was well received

  • How to open PDF stored as blob

    Hi, How can i open PDF that is stored in the database as BLOB from Forms 10g. Any method to directly open the PDF instead of generating physical PDF file in AS and open in client by webutil.showdocument. Thanks in advance

  • [SOLVED] dwm Compiling Error

    Hello, I am running dwm, and I love how simple and light it is. I edited my config.h few times and compiled it and it was fine. The last time I tried, it gave me an error. I could not figure that out. I tried to use a valid config.h from the internet