Wish to find out number of rows returned from query

hi,
is it possible to determine how many rows have been returned after a query has been executed?
thank you.

It doesn't seem like there is a method to do it for you, [...]There can't be such a method that's guaranteed to work for all databases. Many databases just hand you a cursor with the query results, and you have to walk the cursor to find the complete set. It's even possible for the DB to continue computing the query in the background and just give you a cursor to walk and consume what it has already generated.
So no, you have to walk the result set (effectively pulling everything over to the client) to count the number of rows..

Similar Messages

  • 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

  • Getting the number of rows returned from ResultSet

    Hi,
    Does anyone know a method to get the number of rows returned with a query using the Resultset class?
    Thanks.

    Hi 281080,
    If your database and JDBC driver support it, in order to use the solution that da-alexj has suggested, you need to create a 'scrollable' "ResultSet" -- the javadoc for method "createStatement()" (in class "java.sql.Connection") has more details.
    However, I have found with Oracle 8.1.7.4 database and Oracle (thin) JDBC driver, that part of their implementation of the "last()" method (in class "java.sql.ResultSet") is to actually iterate through the entire "ResultSet" in order to reach the last row. If your "ResultSet" is very large (I tested it with a 100,000 row "ResultSet"), this will take a long time.
    Just wanted to make you aware of that.
    Of-course, this may be irrelevant to you since I didn't see any mention in your post of what database and JDBC driver you are using.
    Hope this has helped you, anyway.
    Good Luck,
    Avi.

  • How to get total number of rows return by query

    hi all
    i am using forms 6i with oracle 10G in windows environment....
    i have a tabular form now i want to know that how many rows return by the query...like when user click on enter query and then give any search criteria and then execute query..it displays the records but i want to count the records that how many rows are return.............
    hope you understant what i mean
    Thanks in advance
    Regards

    U can use
    "Select count(*) from <table> where <condition>"
    <condition> is the where clause being used during "Execute Query"
    this will give u the no of records in query.
    And second option is to take a summary column. whose function is set "COUNT" and
    "Summarized item" should contain a column that will never be blank. After execute query this column will give u no of records in block.
    Regards....

  • Find out number of rows of an ALV table

    I would like to implement a generic method that returns the number of lines that are shown in an ALV table. Is this possible? Can I retrieve this information from the ALV model, or do I have to check the context for this?

    Hi Daniel,
    The iwci_salv_wd_table interface (the interface used which implements the method GET_MODEL), also has the method WD_GET_API, which returns a reference to IF_WD_CONTROLLER. This interface implements methods which will return the context information.
    Hope this helps
    Regards,
    Wenonah

  • Incorrect Number of rows returned from Toplink

    Hi,
    Lets say I have hierarchy as :- A has bCollection and cCollection. I write a readobjectquery for A and specify both bCollection and cCollection as joinedAttribute and provide filter criterion for A which gives unique record.
    The data is setup in such a way that there are two instances of B for given condition and 4 of C.
    When I query with filter condition for B, i get correct collection size for both B and C. But if I I introduce a filter condition for bCollection, the very first record of cCollection is getting stripped off. But I do see the same if I execute the query that Toplink fired. This is really weird as just the first record is missing.
    Did anyone ever faced similar probelm ? (record count mismatch from toplink query and toplink objects ?)
    TIA
    Ani

    Hello Ani,
    When you say "But I do see the same if I execute the query that Toplink fired", do you mean you see the correct results if you execute the SQL on your database or that you see the same results TopLink gives you? Also, what version of TopLink are you using and have you applied the latest patchset?
    Best Regards,
    Chris

  • Pick the last row returned from query

    hii...
    i have a query thats returns...
    SQL> WITH tbl_zone AS (
      2       SELECT to_date('02/03/2010', 'DD/MM/YYYY') close_date FROM dual UNION ALL
      3       SELECT to_date('03/03/2010', 'DD/MM/YYYY') FROM dual UNION ALL
      4       SELECT to_date('04/03/2010', 'DD/MM/YYYY') FROM dual UNION ALL
      5       SELECT to_date('09/03/2010', 'DD/MM/YYYY') FROM dual UNION ALL
      6       SELECT to_date('11/03/2010', 'DD/MM/YYYY') FROM dual)
      7    SELECT  TRUNC(close_date, 'IW') close_date
      8   from tbl_zone t
      9   ORDER BY 1 DESC;
    CLOSE_DATE
    08/03/2010
    08/03/2010
    01/03/2010
    01/03/2010
    01/03/2010i want the query to return just i row and that should be the greatest date
    in the above example
    the query should return single row out of the 2 greatest dates, 08/03/2010.
    CLOSE_DATE
    08/03/2010Please any one suggest...

    How about row_number()
    SQL> with tbl_zone as (
      2       select to_date('02/03/2010', 'dd/mm/yyyy') close_date from dual union all
      3       select to_date('03/03/2010', 'dd/mm/yyyy') from dual union all
      4       select to_date('04/03/2010', 'dd/mm/yyyy') from dual union all
      5       select to_date('09/03/2010', 'dd/mm/yyyy') from dual union all
      6       select to_date('11/03/2010', 'dd/mm/yyyy') from dual
      7       )
      8  --
      9  --
    10  --
    11  select close_date
    12  from ( select trunc(close_date, 'iw') close_date
    13         ,      row_number() over ( order by close_date desc)  rn
    14         from   tbl_zone t
    15       )      
    16  where rn=1;
    CLOSE_DATE
    08-03-2010 00:00:00

  • Can u find (number of rows) + (SELECT * FROM emp) in 1 query?

    We have a requirement like this: We need to pass a SQL statement as a SYS_REFCURSOR OUT variable from a SP. Problem is, if the SQL returned 0 rows we have to send 1 row with all NULLS to the SYS_REFCURSOR.
    Is there any way to find out the number of rows returned from a SQL without having to put a SELECT COUNT(*) again using the "same" SQL?

    Peter:
    That only works if the cursor actually returns rows. Consider:
    SQL> create table t as
      2  select rownum id, to_char(to_date(rownum, 'J'), 'Jsp') descr
      3  from user_objects
      4  where rownum <= 5;
    Table created.
    SQL> insert into t select * from t;
    5 rows created.
    SQL> commit;
    Commit complete.
    SQL> create function f (p_id in number) return sys_refcursor as
      2     l_cur sys_refcursor;
      3  begin
      4     open l_cur for
      5        select id, descr, count(*) over() cnt
      6        from t
      7        where id = p_id;
      8     return l_cur;
      9  end;
    10  /
    Function created.
    SQL> var cur refcursor
    SQL> exec :cur := f(1);
    PL/SQL procedure successfully completed.
    SQL> print cur
            ID DESCR             CNT
             1 One                 2
             1 One                 2
    SQL> exec :cur := f(42);
    PL/SQL procedure successfully completed.
    SQL> print cur
    no rows selectedSince the OP's requirement (or ""solution" coming from someone who misunderstood the concept of cursors") is that "if the SQL returned 0 rows we have to send 1 row with all NULLS to the SYS_REFCURSOR" the analytic count doesn't help.
    @OP
    The only reliable (for certain definitions of reliable) way would be to consume the first row of the cursor to see if it did in fact return any rows.
    However, if the cursor was initally empty, we then need to generate a new cursor with all NULLS to satisfy the request. Not a big deal, as the new cursor would reflect the state of the database at the time of the initial query, even if a qualifying row was inserted and committed between the first query and the second, but it doesn't work the other way around.
    If I consume the first row and find a record, then I need to re-do the query to get all of the rows. but what happens if another process changes/deletes the qualifying row in between and commits? The second query will have no rows and you will return an empty cursor to the caller.
    Also, counting the rows (which the analytic count will need to do) could have a significant impact on performance since all the qualifying rows need to be read before the first row can be returned.
    John

  • Number of rows returned in a query

    Is there a way to get the number of rows returned from a query without itterating through the itterator?
    Thanks,
    Yon

    No.
    Because rows are not all returned until you start interating.
    Some times I have seen people do a count query before the normal query, this helps out if you need a count to set things up.

  • Is it possible to count the rows returned from a query?

    Hello,
    When using JDBC is there anyway of finding out the number of
    rows returned from a query before actually getting each row?
    In Forms 4.5 you can use the count_query function, does anyone
    know of an equivalent function or work around in JDBC and/or
    SQLJ?
    Thanks.
    null

    Pasi Hmlinen (guest) wrote:
    : Try
    : SELECT COUNT(*) FROM the_table WHERE <conditions>;
    : Hope this helps,
    : Pasi
    Thanks for the advice, I'm currently using SELECT COUNT(*) but
    I'm looking for a more efficient way of doing it. If I SELECT
    COUNT each time then I have to prepare and execute a SQL
    statement each time. What I want to do it execute a single SQL
    statement to return my results and somehow find out the number
    of rows in the resultset without having to go back to the
    database.
    Gethin.
    null

  • How to get number of rows return in SELECT query

    i'm very new in java, i have a question:
    - How to get number of rows return in SELECT query?
    (i use SQL Server 2000 Driver for JDBC and everything are done, i only want to know problems above)
    Thanks.

    make the result set scroll insensitve, do rs.last(), get the row num, and call rs.beforeFirst(), then you can process the result set like you currently do.
             String sql = "select * from testing";
             PreparedStatement ps =
              con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
             ResultSet rs = ps.executeQuery();
             rs.last();
             System.out.println("Row count = " + rs.getRow());
             rs.beforeFirst();~Tim
    NOTE: Ugly, but does the trick.

  • How do I find the number of users returned by a cfldap query?

    How do I find the number of users returned by a cfldap query?
    I'm not allowed to do something like:
    <cfif ArrayLen(results.rows) gt 1>
    I then get an error:
    faultCode:Server.Processing faultString:'Unable to invoke CFC - Object of type class coldfusion.tagext.net.LdapResultTable cannot be used as an array' faultDetail:''
    Many thanks for any light you can shed

       Cheers again Ian for your many helps,
    it now won't let me do
    <cfqueryparam value="#results.USNCreated#" cfsqltype="cf_sql_varchar">
    I get the message:
    faultCode:Server.Processing faultString:'Unable to invoke CFC - Error Executing Database Query.' faultDetail:'[Macromedia][SQLServer JDBC Driver][SQLServer]The name "results.USNCreated" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.'

  • Trying to find the number of rows in a ResultSet

    I am trying to find the number of rows in a ResultSet, using the following code:
    rs = st.executeQuery(query);
    rs.last(); // to move the cursor to the last row
    System.out.println(rs.getRow());
    However, I am getting this error:
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unsupported method: ResultSet.last
    Whats going wrong??

    praveen_potru wrote:
    You might have not used scrollable result set..
    Try like this:
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);rs = stmt.executeQuery(sqlString);
    // Point to the last row in resultset.
    rs.last();
    // Get the row position which is also the number of rows in the ResultSet.
    int rowcount = rs.getRow();
    System.out.println("Total rows for the query: "+rowcount);
    cheersAnd I hope the OP would read it because the thread is a year old.

  • How can I limit the number of rows returned by a select stat

    How can I limit the number of rows returned by a select
    statement. I have a query where I return the number of stores
    that are located in a given area.. I only want to return the
    first twenty-five stores. In some instances there may be over
    200 stores in a given location.
    I know is SQL 7 that I can set the pagesize to be 25....
    Anything similiar in Oracle 8i?
    null

    Debbie (guest) wrote:
    : Chad Nale (guest) wrote:
    : : How can I limit the number of rows returned by a select
    : : statement. I have a query where I return the number of
    : stores
    : : that are located in a given area.. I only want to return the
    : : first twenty-five stores. In some instances there may be
    : over
    : : 200 stores in a given location.
    : : I know is SQL 7 that I can set the pagesize to be 25....
    : : Anything similiar in Oracle 8i?
    : If you are in Sql*Plus, you could add the statement
    : WHERE rownum <= 25
    : Used together with an appropriate ORDER BY you
    : could get the first 25 stores.
    Watch out. ROWNUM is run before ORDER BY so this would only
    order the 25 selected
    null

  • Can we find the number of rows in table from the dump file

    Hi All,
    Can we find the number of rows in table from the dump file with out importing the table in to the database?
    Please let me know ,if any option is there.
    Thanks,
    Kumar.

    <s>Try to import with option SHOW=Y, that should skip the number of rows which are into a table from a dump file.</s><br>
    <br>
    Nicolas.<br>
    Oops, sorry, that doesn't show the number of lines...<br>
    Message was edited by: <br>
    N. Gasparotto

Maybe you are looking for

  • I am unable to get same preview image colors in Bridge and Lightroom

    I am unable to get same file preview in Bridge and Lightroom. The Lightroom preview image (in both the Library and Develop) is more de-saturated. But the exported/saved jpegs match. If I try to match the Lightroom preview image to the Bridge preview

  • A suggestion for next version

    Under Party Shuffle we have "more likely", "less likely" and "random". I'd like a "never repeat"

  • Problem about BIEE Integration with LDAP

    Hello, I have a problem in OBIEE11.1.1.6 I do BI EE 11g Security Integration with OPENLDAP follow below link, http://www.rittmanmead.com/2010/11/oracle-bi-ee-11g-security-integration-with-microsoft-active-directory/ It works well using user that stor

  • Home sharing 11.1.5

    Hi - in our house we have 2 set-ups. Mine, iPad, iPhone, iMac and daughters iPod all connected to iMac iTunes using my Apple ID - all music and films are synced and everything works. Apple Tv is also connected and works great. My wife has her Mac Air

  • Creative Cloud desktop application won't install

    The download box flickers for a few seconds and then nothing happens... Can't download any programs as a result. Anyone have ideas?