How to count no of records returned from a query?

I need to find out how many records displayed from a query without writing any other queries.
i mean that.
I have a query such as:
query = "select * from users";
and the resultset for it is rs.
and i need to display how many records fetched from this query without using any other query such as "select count(user_id) from users" etc.
Is there any function ?

No, unfortunately there is no method or property that will tell you how many rows have been returned by a query.
People use many different techniques.
1.The simplest would be, keep incrementing a counter in while ( ) and at the end you'll have the count. But only at the end, after the loop.
2. Run another query with count(*) just to fetch the count.
3. Run the same query twice, once for counting and then again for printing out. Very dumb idea though, might as well do 2. suggested above.
4. If you have a scrollable resultset, you could go to the lastRecord and then getRow number and hence know how many there are and then rewind the resultset. I don't know how advisable using scrollable resultsets is.
5. Create a slightly clumsy query like : select count(*) as "totalcount", emp_id, emp_name, emp_email, emp_phone from employees group by emp_id, emp_name, emp_email, emp_phone. You'll need to use the group by clause since count() is an aggregate function and you can't mix aggregate functions and columns unless you add the group by to all the columns you're fetching.

Similar Messages

  • Periodic Alert-How to send all the records returned from the SQL in a mail?

    Hello all,
    I have defined a Periodic Alert, my SQL query returns more than one record whenever I run it. I also defined an action to send an email with the message consisting of the output variables from the SQL. Whenever i run this alert, a mail is being sent for every single record returned from the query. But i want to send a single mail containing all the records information that my SQL query returns.
    For Example: My SQL query lists all the users created on current date.
    Select User_Id, User_Name into &OUTPUT1, &OUTPUT2
    from fnd_users where trunc(creation_date) = trunc(sysdate)
    Now i want to send a mail with all the users information from the above query, to SYSADMIN. How can this be achieved?
    Thanks & Regards

    Hi Chakoo,
    If the Periodic Alert is not working as requried. You can write a simple package with 3 procedures to implement the writing output to a out file and simultaneuosly send email to multiple receiptents.
    Create Package xx_pac
    Create public Procedure P1
    Select User_Id, User_Name into &OUTPUT1, &OUTPUT2
    from fnd_users where trunc(creation_date) = trunc(sysdate)
    fnd_file.put_line (fnd_file.output, &OUTPUT1, &OUTPUT2);
    (Create private Procedure P2
    ---Write the email package using the UTL_SMTP approch. Using this approch you can send the procedure P1 output file as an attachment to the desiginated receiptents.
    (Create public Procedure P3
    ---call the procedure P1 using the "g_request_id = fnd_request.submit_request"
    ---Wait for the above procedure to complete using "l_conc_status := fnd_concurrent.wait_for_request" procedure.
    ---call the procedure P2. (When called you must provide the correct to, from address)
    Register the Package xx_pac as a concurrent program and schedule when submit it from the request.
    Arun Rathod

  • How to display first row value returened from a query as checked as default in a report

    How to display first row value returned from a query as checked as default in a report
    Parameter 1

    Hi Mudassar,
    The issue is caused by the order in which the parameters appear in the report data tab can be difference between our report execution and it failing. In other words, “Parameter2” is execution before parameter “A” due to this issue. We can adjust the parameter’s
    order to solve the issue.
    If “Parameter2” is parameter “A”, we cannot use that expression. Because fields cannot be used in report parameter expression, if we want to display the first value returned from a query as default value, we have to fill the “Specify values” text box with
    the specific value in Default Values dialog box.
    Alisa Tang
    Alisa Tang
    TechNet Community Support

  • How-To Display the Number of Records Returned from a List to the User?

    We currently are using lists to identify accounts that meet various criteria. Because the territories vary from 4k to 60k customers the users have stated that they don't know the size of the list and therefore don't know if they need to refine the list. Currently they are exporting to Excel to look at the row count to see if they need to further refine their searches. This takes quite a while and while shuffling through many lists is a bit painful. Isn't there a way to just show the total records returned from the list down at the bottom of the screen where it allows you to see 25/50/75/100 records at a time?
    There is probably a simple way to do this but it is a large user dissatisfier at the time because we simply don't know how to make this show up. Again we are using lists and not analytics for simple lists at this time.
    - john
    Edited by: user11286597 on Jun 19, 2009 11:02 AM

    Thanks Bobb. I can't believe that one wasn't in R1 :)
    Is there a link to the items being worked in the next release by any chance?
    - john

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

    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

    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

  • How do I reed a carrige return from a JTextArea

    How do I reed a carrige return from a JTextArea, as i would like to hadel this with a button press event.

    Try adding a keyListener and use the appropriate method to get the key used from the passed in KeyEvent
    public void keyPressed(KeyEvent e) {
    if(e.getKeyStroke() == KeyEvent.VK_ENTER) {
    ... // the rest goes here. Please check this code for it is not tested

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

    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 =
             ResultSet rs = ps.executeQuery();
             System.out.println("Row count = " + rs.getRow());
    NOTE: Ugly, but does the trick.

  • How to retrieve dynamic filter value submitted from control query to .....

    How to retrieve dynamic filter value submitted from control query to broadcast query.....
    I'm trying to change the hierarchy version determined by a userexit variable in the broadcast query.
    The Hierarchy Version should be dependent on the input filter delivered by the bursting query.
    But how do I catch the dynamic filter value which has been submitted by the bursting query,
    with other words:  where does the bursting query store it's out put while sequentially starting the broadcast query value by value?
    BTW: the filter value from the bursting query appears under "dynamic filter values" in the information of the broadcast query...
    Any thoughts are welcome!
    Edited by: Heinrich Krupp on Jun 24, 2009 1:25 PM

    Further information,
    Report is used via webi only, not Xcelsius or Dashboard.
    Report is consuming BI Web Services.
    Although we can pass in prompt values to BI Services, I couldn't find if we could pass a variable or dimension object into this field. Anyone knows?

  • XMLAttribute unable to handle multiple values returning from a query

    Hi Guys,
    I have to design the format of the data returning from a query in XML. For this i have used xmlelement and xmlattribute
    the query goes like this
    SELECT '<?xml version="1.0" ?>'||' '||XMLELEMENT("imageData",
    XMLATTRIBUTES(LI.GROUPNO as "imageName", 'PNG'as "imageType", '2.0' as "version", '' as "xmlns"),
    XMLATTRIBUTES('roundedRectangle' as "shape"),
    here he logic is the one groupno from pfealigil and the corresponding pnc_keyno that are related to groupno are fetched here. but here since multiple pnc_keyno are returning xmlattributes is unable to handle. I want to design the xml in this format
    <?xml version="1.0" ?>
    <imageData imageName="ISDH0001104"
    imageType="PNG" version="2.0" xmlns="">
    <callouts shape="roundedRectangle">
    <callout label="182">
    <point x="289" y="68"/>
    <callout label="247"<point x="430" y="83"/>
    <callout label="122"><point x="546" y="331"/>
    <callout label="249"><point x="402" y="429"/>
    <callout label="248"><point x="392" y="463"/>
    <callout label="182"><point x="228" y="416"/>
    <callout label="1"><point x="364" y="737"/>
    <callout label="14"><point x="494" y="980"/>
    <callout label="168"><point x="671" y="910"/>
    <callout label="15"><point x="779" y="848"/>
    <callout label="1"><point x="805" y="343"/>
    like here one image name all those pnc_keyno that are valid should come in this way as above. Please let me know if anything is unclear to you

    apexStarter wrote:
    Data model goes like thisYou mentioned two tables in your first post, but I guess it's just a matter of joining them to get the above resultset?
    In this case you can do it like this :
    SQL> WITH sample_data AS (
      2    SELECT '91-921' groupno, '1125AE' pnc_keyno, 000000127 coordinatesx1, 000000730 coordinatesy1 FROM dual UNION ALL
      3    SELECT '91-921', '18642F', 000000513, 000000891 FROM dual UNION ALL
      4    SELECT '91-921', '18643D', 000000620, 000000844 FROM dual UNION ALL
      5    SELECT '91-921', '18649E', 000000561, 000000688 FROM dual UNION ALL
      6    SELECT '91-921', '18668B', 000000620, 000000864 FROM dual UNION ALL
      7    SELECT '91-921', '92101A', 000000587, 000000591 FROM dual UNION ALL
      8    SELECT '91-921', '92102A', 000000587, 000000571 FROM dual UNION ALL
      9    SELECT '91-924', '1243BD', 000000617, 000000889 FROM dual
    10  )
    11  SELECT XMLRoot(
    12           XMLElement("imageData",
    13             XMLAttributes(
    14               groupno as "imageName"
    15             , 'PNG'as "imageType"
    16             , '2.0' as "version"
    17             , '' as "xmlns"
    18             )
    19           , XMLElement("callouts",
    20               XMLAttributes('roundedRectangle' as "shape")
    21             , XMLAgg(
    22                 XMLElement("callout",
    23                   XMLAttributes(pnc_keyno as "label")
    24                 , XMLElement("point",
    25                     XMLAttributes(
    26                       coordinatesx1 as "x"
    27                     , coordinatesy1 as "y"
    28                     )
    29                   )
    30                 )
    31               )
    32             )
    33           )
    34         , version '1.0'
    35         )
    36  FROM sample_data
    37  GROUP BY groupno
    38  ;
    <?xml version="1.0"?>
    <imageData imageName="91-921" imageType="PNG" version="2.0" xmlns="">
      <callouts shape="roundedRectangle">
        <callout label="1125AE">
          <point x="127" y="730"/>
        <callout label="92102A">
          <point x="587" y="571"/>
        <callout label="92101A">
          <point x="587" y="591"/>
        <callout label="18668B">
          <point x="620" y="864"/>
        <callout label="18649E">
          <point x="561" y="688"/>
        <callout label="18643D">
          <point x="620" y="844"/>
        <callout label="18642F">
          <point x="513" y="891"/>
    <?xml version="1.0"?>
    <imageData imageName="91-924" imageType="PNG" version="2.0" xmlns="">
      <callouts shape="roundedRectangle">
        <callout label="1243BD">
          <point x="617" y="889"/>

  • How to count number  of records for a field based on condition?

    Hi guys,
    I want to know how to find count of records coming from the database for a particular field based on some condition.
    I need to use this count to suppress some headers. Because of this i am not able to use running totals. Is there any other way?
    Ex scenario:
    I have account number and currency fields, those are coming from database. And i need to count the number of accounts whose currency is not Euro.
    Thanks in advance,

    A simple formula can do that:
    //Formula begin
    if {your account field}<>"Euro" then 1
    //Formula end
    This formula can be summarized. (by group or report)
    Bryan Tsou@Taiwan

  • How to compare a boolean value returned from a function in a sql query

    Hi all
    i have a function which return boolean true or false.
    mean while i am writing a sql query which should check this function and will return a result set only when it is true. how will i use a function which returns boolean in a sql query..
    thanks in advance'

    I don't think this is possible - i'm not sure. Can you post your function script? The reason why am i asking this is --
    satyaki>set serveroutput on
    satyaki>create or replace function test_satf(emno in number)
      2  return boolean
      3  is
      4    v_cnt   number(5);
      5    v_flg   boolean;
      6  begin
      7    select count(*)
      8    into v_cnt
      9    from emp
    10    where empno = emno;
    12    if v_cnt = 1 then
    13       v_flg := TRUE;
    14    else
    15       v_flg := FALSE;
    16    end if;
    18    return v_flg;
    19  exception
    20    when others then
    21      v_flg := FALSE;
    22   return v_flg;
    23  end;
    24  /
    Function created.
    satyaki>desc emp;
    Name                                      Null?    Type
    EMPNO                                     NOT NULL NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO                                             NUMBER(2)
    satyaki>select count(*) from emp;
    satyaki>select empno,test_satf(empno)
      2  from emp;
    select empno,test_satf(empno)
    ERROR at line 1:
    ORA-06552: PL/SQL: Statement ignored
    ORA-06553: PLS-382: expression is of wrong type
    satyaki>select to_char(test_satf(empno))
      2  from emp;
    select to_char(test_satf(empno))
    ERROR at line 1:
    ORA-06552: PL/SQL: Statement ignored
    ORA-06553: PLS-382: expression is of wrong type
    satyaki>create or replace function test_satf(emno in number)
      2  return varchar2
      3  is
      4    v_cnt   number(5);
      5    v_flg   varchar2(10);
      6  begin
      7    select count(*)
      8    into v_cnt
      9    from emp
    10    where empno = emno;
    12    if v_cnt = 1 then
    13       v_flg := 'TRUE';
    14    else
    15       v_flg := 'FALSE';
    16    end if;
    18    return v_flg;
    19  exception
    20    when others then
    21      v_flg := 'FALSE';
    22   return v_flg;
    23  end;
    24  /
    Function created.
    satyaki>select test_satf(empno)
      2  from emp;
    14 rows selected.Or, may be i'm missing something.
    Satyaki De.

  • How to check if the approver returned from AME is the last apporver

    I have setup multiple Approval Groups which uses a query to derive the approver list. Each Self Service HRMS transaction is attached to a different approver group.
    My requirement is to write a function in Workflow to check if the approver returned from AME is the last approver of the group.
    Please let me know how I can achieve this.

    there is some seeded attribute like is_last_approver. Check the value if this returns tru then it is last approver

  • Dynamic Pages: how to overide the default format returned from the oracle query.

    When writing a dynamic page, portal always displays any return from a database query in a default format or grey background table:
    <TABLE border="0" cellspacing=0 cellpadding=2 style="background-color:#E0E0D0">
    <TH ALIGN="LEFT" style="background-color:#C0C0A0" > </TH>
    <TD ALIGN="LEFT" valign="TOP" WIDTH="0">
    Is there anyway to change this or this how the
    function always works?
    Thanks in advance!

    Please see posting
    Just a reminder, please search the forum before posting your question. It's quite likely that someone else has already asked the same question.

  • How to create COGSuFF0Cwhen goods was returned from customer

        goods which deliveried from nonvaluated sales order stock was returned from customer and reduce revenue and AR.
    so, we need do following process:
        create returned sales order〉delivery note and goods receipted-〉billing
      the goods can be receipted in sales order stock ,and can be invoiced .
    but how to create COGS  with returened sales order for nonvaluated sales order stock?

      T-CODE :MR21 ,It is used to change the standard price ,we are in the environment that make to order with nonvaluated sales order stock ,so donu2019t need do standard coting .
    I konw : With a nonvaluated sales order stock, inventory changes are not reflected in Financial Accounting. The sales order stock is settled to Financial Accounting only after results analysis and settlement of the calculated values (results analysis data) .
      for normal process , if billing was created ,then do results analysis and settlement of the calculated values ,COGS will be post in financial accounting
      for returen prcoess :
      1. created returen sales order and referenced origin billing document.
       2. create delivery note and goods receipted in sales order stock which was deliveried to customer stock
      3. create billing document and revenue posted in financial accounting
       4. do results analysis with returen sales order ,the system show error message:               W     KJ     816     No object was selected
         when used the orign sales order to do results analysis ,but without any change to save !
    how to post COGS in financial accounting ,when goods was return from cusromer in the environment that make to order with nonvaluated sales order stock ?

  • How to count the number of parameters from  consumer(ex.soapUI)?

    I am a beginner is OSB. I am working on a task that has to count the no.of .parameters from the consumer(Soap UI) in the proxy service. And if the parameter is lesser than 4 an error has to be thrown else it should be routed to another business service. Anyone worked on such scenario before?

    Thanks for the quick reply. I will explain the approach i followed, not sure whether it is correct or not.
    I haven't used any WSDL fiile , instead i used the xquery file.
    In the proxy service assign node i tried to catch the parameters using $inbound/ctx:transport/ctx:request/http:query-string/text() and assigned it to a variable.
    I have configured the assign node with the xquery file, here extracted the parameters using.
    declare function xf:parseRelativeURI($string1 as xs:string)
    as element(ns0:LNIGeneratorRequest) {
                   <ns0:partitionId> {xf:getParameter($string1,"partitionid=")}</ns0:partitionId>
                   <ns0:type> {xf:getParameter($string1,"type=")}</ns0:type>
                   <ns0:clientInfo> {xf:getParameter($string1,"clientinfo=")}</ns0:clientInfo>
    Then in the replace node i had replaced it with the "body" variable.
    All the conditions i had place in the xquery file. like below
    declare function xf:getParameterCount() as xs:integer{
    let $queryParams := xf:parseRelativeURI($string1)
    let $countParams := fn:count($queryParams/child::*)
    let $error := 0
    let $success := 1
    return if($countParams<10)
    then $error
    else $success
    Thanks in Advance

Maybe you are looking for

  • This iphone could not be synced because this computer is no longer authorised but i try again and it says already authorised

    I am trying to sync my iphone 4 to my computer ( Windows 7 64 bit ) so I can update my apps. when I connect my phone to the computer, a window pos up with the following . . . . . . . . . this iphone 'colin's iphone' could not be synced because this c

  • High quality images in indesign CS6 get pixelated

    I have been using indesign CS6 for a while now. Recently, when I place some images into a document, they are pixelated. They are high quality images with a high resolution. Even when I shrink it down considerably to fit in the document, it still gets

  • Problem in receiving messages via RFC Sender Adapter

    Hi, I have problems in receiving messages from SAP backens systems. Sometimes we are getting all messages sometimes not. Strange. We are transfering report-results via asynchronous RFC calls. To avoid big message sizes we split them up in max. 1000 r

  • Time Machine back up failed

    i have a 1tb time capsule and since activating iCloud my back up fails, insufficent disc space, however I have only used 653GB on my iMAC HD, any suggestions welcome

  • Datatable empty query result

    when i execute a query in a datatable object, and the query result is empty (0 rows) then the datatable object contains 1 row (with empty strings and zero's).. Why??? Is there a way to determine from this if the queryresult was empty (and not an empt