How to count no of records returned from a query?

Hello,
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 ( rs.next() ) 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
    chakoo

    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.
    Example:
    Create Package xx_pac
    Create public Procedure P1
    begin
    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);
    end;
    (Create private Procedure P2
    begin
    ---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.
    end;
    (Create public Procedure P3
    begin
    ---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)
    end;
    end;
    Register the Package xx_pac as a concurrent program and schedule when submit it from the request.
    Regards
    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
    Example
    Parameter 1
    Paramerter2
    ABD
    x(checked)
    Test
    DEF
    JMG
    Mudassar

    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.
    Regards,
    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?

    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 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
    }ICE

  • 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 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", 'com.snapon.sbs' as "xmlns"),
    XMLELEMENT("callouts",
    XMLATTRIBUTES('roundedRectangle' as "shape"),
    XMLELEMENT("callout",
    XMLATTRIBUTES((SELECT IO.PNC_KEYNO FROM PFEALIOCR IO WHERE IO.BASECATALOGNO = LI.BASECATALOGNO AND LI.GROUPNO = IO.GROUPNO) as "label"),
    XMLELEMENT("point",
    XMLATTRIBUTES((SELECT IO.COORDINATESX1 FROM PFEALIOCR IO WHERE IO.BASECATALOGNO = LI.BASECATALOGNO AND LI.GROUPNO = IO.GROUPNO) as "x",(SELECT IO.COORDINATESY1 FROM PFEALIOCR IO WHERE IO.BASECATALOGNO = LI.BASECATALOGNO AND LI.GROUPNO = IO.GROUPNO) as "y")))))
    FROM PFEALIGIL LI
    WHERE LI.DELETEFLAG <> 'D'
    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="com.snapon.sbs">
    <callouts shape="roundedRectangle">
    <callout label="182">
    <point x="289" y="68"/>
    </callout>
    <callout label="247"<point x="430" y="83"/>
    </callout>
    <callout label="122"><point x="546" y="331"/>
    </callout>
    <callout label="249"><point x="402" y="429"/>
    </callout>
    <callout label="248"><point x="392" y="463"/>
    </callout>
    <callout label="182"><point x="228" y="416"/>
    </callout>
    <callout label="1"><point x="364" y="737"/>
    </callout>
    <callout label="14"><point x="494" y="980"/>
    </callout>
    <callout label="168"><point x="671" y="910"/>
    </callout>
    <callout label="15"><point x="779" y="848"/>
    </callout>
    <callout label="1"><point x="805" y="343"/>
    </callout>
    </callouts>
    </imageData>
    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             , 'com.snapon.sbs' 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  ;
    XMLROOT(XMLELEMENT("IMAGEDATA",XMLATTRIBUTES(GROUPNOAS"IMAGENAME",'PNG'AS"IMAGETYPE",'2.0'AS"VERSION",'COM.SNAPON.SBS'AS
    <?xml version="1.0"?>
    <imageData imageName="91-921" imageType="PNG" version="2.0" xmlns="com.snapon.sbs">
      <callouts shape="roundedRectangle">
        <callout label="1125AE">
          <point x="127" y="730"/>
        </callout>
        <callout label="92102A">
          <point x="587" y="571"/>
        </callout>
        <callout label="92101A">
          <point x="587" y="591"/>
        </callout>
        <callout label="18668B">
          <point x="620" y="864"/>
        </callout>
        <callout label="18649E">
          <point x="561" y="688"/>
        </callout>
        <callout label="18643D">
          <point x="620" y="844"/>
        </callout>
        <callout label="18642F">
          <point x="513" y="891"/>
        </callout>
      </callouts>
    </imageData>
    <?xml version="1.0"?>
    <imageData imageName="91-924" imageType="PNG" version="2.0" xmlns="com.snapon.sbs">
      <callouts shape="roundedRectangle">
        <callout label="1243BD">
          <point x="617" y="889"/>
        </callout>
      </callouts>
    </imageData>

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

    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'
    Hari

    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>
    satyaki>
    satyaki>
    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;
    11   
    12    if v_cnt = 1 then
    13       v_flg := TRUE;
    14    else
    15       v_flg := FALSE;
    16    end if;
    17   
    18    return v_flg;
    19  exception
    20    when others then
    21      v_flg := FALSE;
    22   return v_flg;
    23  end;
    24  /
    Function created.
    satyaki>
    satyaki>
    satyaki>
    satyaki>
    satyaki>
    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>
    satyaki>
    satyaki>
    satyaki>select count(*) from emp;
      COUNT(*)
            14
    satyaki>
    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>
    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;
    11   
    12    if v_cnt = 1 then
    13       v_flg := 'TRUE';
    14    else
    15       v_flg := 'FALSE';
    16    end if;
    17   
    18    return v_flg;
    19  exception
    20    when others then
    21      v_flg := 'FALSE';
    22   return v_flg;
    23  end;
    24  /
    Function created.
    satyaki>
    satyaki>
    satyaki>select test_satf(empno)
      2  from emp;
    TEST_SATF(EMPNO)
    TRUE
    TRUE
    TRUE
    TRUE
    TRUE
    TRUE
    TRUE
    TRUE
    TRUE
    TRUE
    TRUE
    TEST_SATF(EMPNO)
    TRUE
    TRUE
    TRUE
    14 rows selected.Or, may be i'm missing something.
    Regards.
    Satyaki De.

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

    Hi,
    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.
    Thanks,
    Rachana

    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">
    <TR>
    <TH ALIGN="LEFT" style="background-color:#C0C0A0" > </TH>
    </TR>
    <TD ALIGN="LEFT" valign="TOP" WIDTH="0">
    Is there anyway to change this or this how the
    function
    PORTAL30.wwv_render_report.show always works?
    Thanks in advance!

    James,
    Please see posting http://technet.oracle.com:89/ubb/Forum70/HTML/000073.html.
    Just a reminder, please search the forum before posting your question. It's quite likely that someone else has already asked the same question.
    Regards,
    Jerry
    null

  • How to create COGSuFF0Cwhen goods was returned from customer

    Hi,
        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?

    Hi
      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)?

    Hi,
    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:LNIGeneratorRequest>
              <ns0:numberofStampers>{xf:getParameter($string1,"numberofstampers=")}</ns0:numberofStampers>
                   <ns0:partitionId> {xf:getParameter($string1,"partitionid=")}</ns0:partitionId>
                   <ns0:type> {xf:getParameter($string1,"type=")}</ns0:type>
                   <ns0:clientInfo> {xf:getParameter($string1,"clientinfo=")}</ns0:clientInfo>
              </ns0:LNIGeneratorRequest>
    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

  • Note messages at the time of availability check in sales order entry form

    Hello Friends, Im getting the following note messages at the time of availability check in the sales order entry form. ATP Process resulted in no data User defined exception in package OE_SCHEDULE_UTIL Procedure Load_Results_from_rec User defined exc

  • Cannot get onto the web, says firefox is in offline mode

    I cannot access my email, the yahoo page is stuck on yesterdays page, when I try to go to email, it says firefox is in the offline mode and to click the mode key?? How are you going to communicate with me if I am offline??? My # 847-338-0349

  • Loss in Storage capacity

    Mac Book Air   13 inch  2011 128GB  HD OXX Yosemite 10.10 4MB HD storage falls by 2-5 GB in one day with little use

  • Where will new items in managed library go ?

    I am meaning to ask this , supposed if i have ten photos in a project under ABC , i export three of them , delete them from aperture library , do some processing on them , and then drag them back to aperture . Will aperture store them inside the same

  • My problem...

    My aunt and uncle got their daughter an ipod nano for christmas and were trying to set it up. their itunes must have been fairly old and it wasnt working right. so my uncle uninstalled itunes and now heres the problem. the program list says itunes is