Get Number of rows from a sql query.

I am reading data from a sql query in a BLS transaction and I would like to know the number of rows returned.
Is there an easy way to do this without looping through the table?
Thanks Jasper

Hi Jasper,
You can use the XPATH count function similar to  this:
GetTagList.Results{count(/Rowsets/Rowset/Row)}
Kind Regards,
Diana Hoppe

Similar Messages

  • 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.

  • Resukt:Get number of rows from 3 different table...?

    Hi All,
    I need to find out number of rows from 3 different table for the same conditions. Instead of writing 3 queries, is it possible to get it thru one query?
    For example, i need to find out number of rows in tables where name = 'Ameet' from 3 different table, i will end writing 3 queries.
    1. select count(1) from table_a where name = 'Ameet';
    1. select count(1) from table_b where name = 'Ameet';
    1. select count(1) from table_c where name = 'Ameet';
    Is it possible to write a single query to get result of all above 3 queries?
    result:
    table_a table_b table_c
    34 44 2

    One way:
    SELECT      (SELECT     COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet') AS TABLE_A
    ,     (SELECT     COUNT(*) AS CNT FROM TABLE_B WHERE name='Ameet') AS TABLE_B
    ,     (SELECT     COUNT(*) AS CNT FROM TABLE_C WHERE name='Ameet') AS TABLE_C
    FROM DUALIf you want the total:
    SELECT     SUM(CNT)
    FROM
         SELECT     COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet'
         UNION ALL
         SELECT     COUNT(*) FROM TABLE_B WHERE name='Ameet'
         UNION ALL
         SELECT     COUNT(*) FROM TABLE_C WHERE name='Ameet'
    )

  • How to get thr number of rows of an SQL query in JSTL

    hi guys,
    can anyone please tell me how do i perform a function which finds out the particular rownumber of an sql query in JSTL.....
    the same code in jsp is:
    <% plateRSet.getRowNum() %>
    how do i do this given plateRset is the var for a given iteration
    thanks
    rahul

    make your result set scrollable...Not such a good idea. With Oracle, the JDBC driver will read and cache all the ResultSet in memory (with other DBMSs/drivers the behavior will probably be different, but you will still have some unnecessary overhead).
    You can do the caching yourself if you think it's worth it. If the piece of code you posted is why you need this for, then use a List or Vector and you won't need to know the size upfront.
    Alin,
    The jTDS Project.

  • How do I get last 15 rows from a select query

    Hello,
    I am writing a query, and I need to filter the last 15 rows of from the select query.
    For example: Select id, name,join_date from emp order by join_date;
    So I need to get the last 15 rows from emp table so that we can who are the last 15 employees joined the organization. I want to show the result in ascending order, otherwise I would have taken first 15 rows with order by clause as descinding order.
    Thanks in advance,
    Param.

    SQL> select ename, join_date from test222
    2 where rownum < 6
    3 order by join_date
    4 /
    ENAME JOIN_DATE
    CNC5461177794 14-FEB-02
    OR91551178218 14-FEB-02
    TUB9894676495 14-FEB-02
    SG15431177117 14-FEB-02
    PIB9384674017 14-FEB-02
    SQL> SELECT * from
    2 (select ename, join_date from test222
    3 order by join_date desc)
    4 WHERE rownum < 6
    5 /
    ENAME JOIN_DATE
    II61111208401 19-MAR-02
    II61451208038 18-MAR-02
    PI20014184983 01-MAR-02
    BNF2221148037C 28-FEB-02
    UO78902581 18-FEB-02
    Can you see the problem now ?
    You can test this concept with your own table.
    have a good day,
    Sri

  • Need to retrieve number of rows affected by SQL query

    Hi,
    I am executing some update queries in SQL in a xMII transaction. Iam using a SQL Query template for the same and I need to find out how many records were affected by the last executed statement. I have tried doing SELECT @@ROWCOUNT in a second SQL template that executes after the UPDATE SQL Query Template. However, the results are intermittent, sometimes it returns 1 row affected as expected but sometimes returns 0 rows. Can anyone help on this.
    Thanks

    Anamika,
    1) As per sql best practices use of trigger is not recommend unless you don't have any other option because usually triggers consume more resources and IO since it involves internal monitoring.
    2) @@ROWCOUNT should go in same SQL session where you are performing update to identify rows affected else as you said earlier your results will not be accurate
    3) The other alternative is to create a Stored Procedure but it again boils down to your authorization issue. This would be easier and better if you have authorization to create SP's. But nevertheless give it a try.
    4) Lets forget about SP say that you have an Update Statement like
    Update Table1 set column2 = 'abc' where Column2 = 'xyz'
    In this case it is evident that you know what you are passing into the Where clause and to what table hence its obvious that you also know how many rows will be affected by using query,
    Select count(*) from Table1 where Column2 = 'abc'
    The @@ROWCOUNT is powerful within t-sql with SP, cursors etc..
    Hope this helps!!
    Regards,
    Adarsh

  • How to get row number in the fetch row itself in Sql Query ?

    Hi,
    i am fetching some rows from a sql query . Is there any way to get row number as well in each row while all rows are fetched ?
    like this :
    RowNum data1 data2
    1 abc ere
    2 bnh ioi

    Hello
    Ofcourse you can get the rownum inside a query, just keep in mind that the rownum is the number of order in which the records were fetched from the table, so if you do an order by, the rownum will not be sequential, unless you query the information in a subquery first.
    SELECT rown, col1, col1
    FROM table
    Or
    SELECT rownum, col1, col2
    FROM (SELECT col_1, col_2 FROM table ORDER BY col1)
    Regards
    Johan

  • How can I get the number of rows in my sql result, without a loop?

    Hello,
    I've a problem, I would like to get the number of rows in my sql result without make a loop like :
    while (rs.next()){
    int number = rs.getRow();
    Is there any method to do this, on the first element?
    Thx, STeF

    If you want to count how many rows are in result set, I dont think you can, but you could always run a count statement for that sql
    say your sql is
    select field1, field2, field3
    from table1, table2
    where field4=field5 ......
    then you can count the rows this statement returns by
    select count(*) from
    (say your sql is
    select field1, field2, field3
    from table1, table2
    where field4=field5 ......)
    This way you will get the count for just that sql

  • System build-in or system variable to get number of records from a query

    Hi,
    Is there a system build-in or system variable to get number of records from a Oracle Forms query?
    Thank you

    Namely, when GO_BLOCK(BLOCK_NAME) EXECUTE QUERY finishes, is there a way directly get the number of the records?
    SYSTEM.COURSOR_RECORD = 1 tells this is the first record
    SYSTEM.LAST_RECORD = 'TRUE' tells this is the last record
    Thanks

  • SQL Query - The number of columns specified in "SQL Query" does not match t

    I am creating new UDM for tablespace alert, below is my query,however its failing with error
    SQL Query - The number of columns specified in "SQL Query" does not match the value specified in "SQL Query Output"
    I selected Metric type is number
    SQL Query Format : Two columns
    Query:
    SELECT d.tablespace_name,round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2)
    used_pct FROM sys.dba_tablespaces d,(select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f
    WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+)
    AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
    Any clues why i am getting error.

    SQL> SELECT d.tablespace_name,round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2) used_pct
    2 FROM sys.dba_tablespaces d,(select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f
    3 WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+)
    4 AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
    TABLESPACE_NAME USED_PCT
    MGMT_TABLESPACE .82
    SYSAUX 1.52
    UNDOTBS1 .32
    RMAN .02
    CORRUPT_TS 10.63
    USERS 0
    SYSTEM 2.26
    MGMT_ECM_DEPOT_TS .04
    MGMT_AD4J_TS 0

  • How can I get the selected rows from two ALV grids at the same time?

    I have a program that uses two ALV grids in one dialog screen. I'm using the OO ALV model (SALV* classes).
    The user can select any number of rows from each grid. Then, when a toolbar pushbutton is pressed, I'd have to retrieve the selected rows from both grids and start some processing with these rows.
    It is no problem to assign event handlers to both grids, and use the CL_SALV_TABLE->GET_SELECTIONS and CL_SALV_SELECTIONS->GET_SELECTED_ROWS methods to find out which rows were marked by the user. Trouble is, this only works when I raise an event in each grid separately, for instance via an own function that I added to the grid's toolbar. So, I can only see the selected rows of the same grid where such an event was raised.
    If I try to do this in the PBO of the dialog screen (that contains the two grids), the result of CL_SALV_SELECTIONS->GET_SELECTED_ROWS will be empty, as the program does not recognize the marked entries in the grids. Also, an event for grid1 does not see the selected rows from grid2 either.
    As it is right now, I can have an own button in both grid's toolbar, select the rows, click on the extra button in each grid (this will tell me what entries were selected per grid). Then, I'd have to click on a third button (the one in the dialog screen's toolbar), and process the selected rows from both grids.
    How can I select the rows, then click on just one button, and process the marked entries from both grids?
    Is it somehow possible to raise an event belonging to each grid programmatically, so that then the corresponding CL_SALV_SELECTIONS->GET_SELECTED_ROWS will work?
    Thanks.

    Hello Tamas ,
    If I try to do this in the PBO of the dialog screen (that contains the two grids), the result of CL_SALV_SELECTIONS->GET_SELECTED_ROWS will be empty, as the program does not recognize the marked entries in the grids. Also, an event for grid1 does not see the selected rows from grid2 either.--->
    is it possible to  have a check box in each grid  & get the selected lines in PAI of the screen ?
    regards
    prabhu

  • How to get number of rows

    Hi!
    Can someone tell me how to obtain the number of rows returned by a query?
    I tried to use getFetchSize() but it seems to always return 0 for my query.
    THANKS in advance!
    ResultSet testRS = Stmt.executeQuery(testStmt);
    int size = testRS.getFetchSize();
    System.out.println("size = " + size);
    Wo Lay

    To get the number of rows returned, you have to loop
    through the result set, or do a "select count" (which
    is more efficient since it doesn't have to pass the
    rows across the network) ...Looping around the entire result set is not very performance efficient. Then agin if you use count (*) you actually execute an extra query.
    The best thing you can do is:// assume res is your result set.
    res.last();
    int rows = res.getRow();This way you only have to execute one query and you don't really need to loop around the entire result set. Of course you will have to have a scrollable result set, if this is supported by your DB.
    Hope that helped.
    afotoglidis

  • How to restrict number of rows returned in a query

    Hi frnds,
    I'd like to restrict number of rows returned by my query to some 10 rows. how to do that.When I try doing with the rownum<10 its giving results for a particular dept and that too some 6 rows only...btw I'm grouping my table and includes joins from many a table and am ordering the table results by a column.. How to do this..

    776317 wrote:
    Hi frnds,
    I'd like to restrict number of rows returned by my query to some 10 rows. how to do that.When I try doing with the rownum<10 its giving results for a particular dept and that too some 6 rows only...btw I'm grouping my table and includes joins from many a table and am ordering the table results by a column.. How to do this..
    TELL ME HOW MANY ROWS YOU HAVE IN TABLE?
    Because you have only *6 rows* in you column, if you less than 10 rows then it displays only containied/exist rows. nothing much
    select ename,empno from emp where rownum < 10;Thanks

  • Retreiving a value from and SQL query

    If anyone can give me sample code or pointers to retreive a value from an sql query, I'd be greatful.
    Source code I've muddled together so far:
    Class seqNumType = Class.forName(nameOfClass);
    Constructor theConstructor = seqNumType.getConstructor(null);
    Object seqNumInstance = theConstructor.newInstance(null);
    String theStatement = "SELECT value INTO v_seqnum FROM DUAL;";
    OracleCallableStatement ocs = (OracleCallableStatement)conn.prepareCall(theStatement);
    ocs.registerOutParameter( 1, OracleTypes.NUMBER, 0);
    Method method = seqNumInstance.getClass().getMethod("getORADataFactory", null);
    seqNumInstance = ocs.getORAData(1, (ORADataFactory)method.invoke(null,null));
    ocs.execute();
    Problem with this seems to be the ORADataFactory isn't a method of the class, but as I'm thumbling around in the dark here a little, I've no idea where to go from here. Is this just generally overkill anyway?
    Suggestions?
    Cheers for any help.

    Like this:
                ResultSet resultSet=statement.executeQuery("SELECT * FROM TEST");
                while(resultSet.next())
                    for(int i=0;i<resultSet.getMetaData().getColumnCount();i++)
                        System.out.print(resultSet.getObject(i+1).toString()+" ");
                    System.out.println();

  • Fastest way to check total number of rows from View ?

    Hello Everyone,
    Good Morning !!!!
    I am trying to know the exact number of rows from a view.
    I have total 262 columns in a view name vw_sample. First column name is col_1 and I do not have permission to view that. but I do have permission to view all other 261 columns. I want to know fastest way to know exact number of rows in this view vw_sample.
    How can i know that ?
    I tried below things.
    1) Tried using COUNT(*) & COUNT(1) but I don't have permission to first column col_1 so that didn't worked.
    2) I do not have permission to view DMV "sys.dm_db_partition_stats"
    3) I tried to execute below code.
    select col_2, col_3,...col_262
    into #TempTable
    from vw_sample
    and it gave me below error
    Msg 1105, Level 17, State 2, Line 1
    Could not allocate space for object '<temporary system object: 9830433781072176840>'
    in database 'tempdb' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.
    4) Accidentaly I run below code
    select col_2, col_3,...col_262
    from vw_sample
    It gave me 11 million rows in 40 minutes. As we know this method is not good to test just number of rows from a view.
    So what would be my option here ?
    Thanks in advance.
    Thanks
    Fredyy

    Fredy, did you try with other column names instead of col1?
    SELECT COUNT(col2) FROM View
    What difference does that make, than using your column 1.
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.
    IMO, sqlsaga's answer is the way to go, but you may need to make a minor change.  When you do COUNT(<some expression>), SQL counts the number of rows where <some expression> is not NULL.  So if col2 can be NULL you need to make a change
    so you know what you are counting can't be NULL.  If there is some other column in the view that can't be NULL, just count it.  Otherwise just use the ISNULL function to convert NULL's to a value.  For example, do
    Select COUNT(IsNull(col2, 0)) From vw_sample
    Note the above assumes that col2 is a type that contains a number (int, numeric, float, etc).  If col2 is of a different type, then just replace the 0 in the above with any valid value of the same type as col2 (so '' for varchar, '19000101' for datetime,
    etc).
    Tom

Maybe you are looking for

  • SNMP v2 compatible agent and system resources

    Hi everybody, I have to provide an SNMP v2 compatible agent (which provides answers to SNMP v2c requests) providing some system resources like cpu consumption, hard disk consumption and disk free space and some specific values through a private MIB.

  • Edge project resizes to 0 height on open

    Hello, I am having a problem with my project stage resizing to 0 when I open the working file. I can set the height and save it but once I open it agian it sets it to zero and I can't preview it as my overflow is set to hidden. Any help would be much

  • How to Create Logo and Favicon with CS6 Quickly ?

    Hello, Shout to Designers ! Hello friends, I'm Piyush and I wanted to create one logo and favicon for SolveMyHow.com Right now you can check it out, the logo looks really bad Plus it doesn't have favicon yet. So, can somebody here suggest me to creat

  • Dependency Manager

    I'm using Dependency Manager in 11g to try and propagate many source data datatype changes through our mappings. The source tables in question have 50 or so columns but when I use Dependency manager to view the impact it only shows 15 columns. I can

  • Keep getting an excepiton(Cx_RSR_Bad_value_combination) in my customer exit

    I keep getting this error.  when i debug the values populate the high & low correctly but I get this error and it shuts down the query.  Here is the code.  I have tried several different things and nothing works.  Any ideas what is wrong.  I am tryin