Calculation of the number of rows in the query object

Hi all
I have a question:

Is there a way to get the number of rows in a query object without running it twice?
I need this for a calculation of total pages.
I can't do something like:
"SELECT COUNT (e) FROM employee e"
because I have a WHERE clause in my expression.

Thank you

I don't think I've had this a simple that you would like to, but I was able to reuse the same query named to account real pagination queries request.

I defined a named query:

        @NamedQuery(name = "Employee.findByNames", query = "select e from Employee e WHERE e.firstName LIKE :FNAME AND e.lastName LIKE :LNAME AND e.gender = :GENDER ORDER BY e.lastName, e.firstName")

Now in the app, I can create an instance of the query for this named query and fill in the parameters using the:

        Query query = em.createNamedQuery("Employee.findByNames");
        query.setParameter("FNAME", "%");
        query.setParameter("LNAME", "%");
        query.setParameter("GENDER", "M");

If I run this query I get all the lines, but instead, I'd like to create an account using the underlying native API query

        ReadAllQuery raq = JpaHelper.getReadAllQuery(query);
        ReportQuery reportQuery = new ReportQuery(raq.getReferenceClass(), new ExpressionBuilder());
        reportQuery.setSelectionCriteria(raq.getSelectionCriteria());
        reportQuery.setOrderByExpressions(raq.getOrderByExpressions());
        reportQuery.setShouldReturnSingleValue(true);
        reportQuery.addCount();
        Query countQuery = JpaHelper.createQuery(reportQuery, em);

        countQuery.setParameter("FNAME", "%");
        countQuery.setParameter("LNAME", "%");
        countQuery.setParameter("GENDER", "M");

        int count = ((Number)countQuery.getSingleResult()).intValue();

Then, for each page of entities wanted the original query is executed as:

        query.setFirstResult(0);
        query.setMaxResults(5);
        List emps = query.getResultList();

Doug

Tags: Fusion Middleware

Similar Questions

  • Filter the table display of the query object (it can a bug in jdev 12)

    Hello:

    I found an error/bug possible in jdeveloper 12 c when I migrate my application of jdev 11g.

    To test this issue, I did the same test request in jdeveloper 11g and jdeveloper 12 c (to avoid to migrate the process).

    Project template

    -Create a display of the query object. Code:

    SELECT 1 CODE, 100 DESCRIPTION
      FROM DUAL
    UNION ALL
    SELECT 2 CODE, 200 DESCRIPTION
      FROM DUAL
    

    -Create a Module of the Application, and then drag this point of view in.

    ViewController project

    -Create a page and drag in the criteria named 'All searchable attributes' of the previous ViewObject as "ADF table filtered.

    -Run the application

    Results:

    On jdeveloper 11g, however it makes the filter above the table box in jdev not 12 c.

    Is this a bug or I need to select something in jdev12c to get the same functionality?

    Yes, known bug 17279781.  It is currently scheduled for a 12.1.4 fix.  If this issue is crucial to you, please file an SR, mentioning the bug number and indicate your reasons for wanting a fix as soon as possible.

    Note there is a solution:

    To work around the problem, you can configure the filter yourself by adding an af:inputText

    facet filter columns and bind the inputText property value to the EL

    #{vs.filterCriteria. }. The page to rerun the filter for

    the column look and work.

    CM.

  • Support - dates in the query object browser!

    Hi all,

    I need help on something simple...

    How can I create a query for the dates in the Explorer objects, Oracle 10g XE?

    I tried: > 1 January 2010 > "January 1, 2010", > 1 January 2010 ", <>January 1, 2010 +... all sorts of diversions and nothing."

    I always have error report:
    ORA-01858: a non-digit character was found here where was waiting for a digital

    I want to just filter a few dates...

    Thank you

    With dates, its generally better to be precise with the date format and does depend not on 'default' well (for American English) January 1, 2011" must have worked, maybe not.

    Are you trying to filter for a specific date, or a beach, that is... where... = or perhaps where between and ...?

    When looking for a date, it may be useful to ignore the component "time" a date with the tronque() function field:

    select ... where trunc( ) = to_date( '01-01-2011','yyyy-mm-dd') ...
    

    Note the to_date with the format mask, which will prevent trouble with assumptions about default date formats (which can also change with the locale... i.e. UK-English customer default date format is "yyyy-mm-dd")

  • limiting the number of rows in a query retrieves

    Is there a way to limit the number of lines extracted by a query?
    where rownum <= :your_limit
    

    Concerning

    Etbin

  • Select a specific number of rows in a query

    How a specific number of lines can be selected in a query? For example, a query retrieves 30 000 files and I want to get the output into groups of 5 000. I want the request to retrieve the first 5,000 records, then then 5,000 cases etc. I tried rownum, but it does not work.


    Thank you
    PANY

    You are welcome.

    (and you can also try a search on "paging query" nicely on this site and http://asktom.oracle.com)

  • Execution of the query against the service

    I wonder what's the difference between running a query on a region that partitioned for a set of objects cached vs using a function distributed to the combined results and return them to the node running?

    The problem, I'm trying make me get all objects from the cache in a region that partitioned a certain type and then perform a calculation on the subject after I he gains the cache to see if it should be added to all final results that I return to my request. I'm not aiming for a specific node for these objects; they can reside anywhere in the partitioned area. Is this the same difference using a query and running the calculation on each object in the result of the query defined in terms of running a distributed function and perform the calculation in distributed mode before returning the results to the running node?

    I think I would use the API to query within the service (Query.execute (RegionFunctionContext)) to query local entries. Are you familiar with the API Query.execute (RegionFunctionContext)? Basically, who runs the query only on local data.

    Then filter these additional results in the function, and then finally to return results filtered out to the customer. Do the same filtering on each local server before returning anything to the client. According to the difference between the result set size and size final filtered results, you will gain a lot of IO, not to mention the serialization/deserialization. You may also be able to do the calculation in the query itself if you have a method for this in the object.

    Barry

  • get the number of rows affected by their table top

    Hello, I need to count the number of rows updated in table form. In the process of ApplyMRU, I can use the string substitution #MRU_COUNT # to show the lines updated in a success message, but I need to get this value and store it on a table. Any help would be much appreciated. Thank you.

    oscarjavier99 wrote:

    Hello, I need to count the number of rows updated in table form. In the process of ApplyMRU, I can use the string substitution #MRU_COUNT # to show the lines updated in a success message, but I need to get this value and store it on a table. Any help would be much appreciated. Thank you.

    For that you would benefit from the APEX$ ROW_STATUS integrated substitution string.

    1. create a page element display only (in my case P15_UPDATED_ROWS) Save Session State set to Yes and the Type of Condition is set to never.

    2. Add a calculation after the shows with a Type of static assignment and calculation value 0 to reset the counter whenever the page is sent.

    3. Add an On submit - after calculations and Validations process of PL/SQL page linked to your tabular presentation with a Status of Type PL/SQL Expression and Expression 1 :apex$row_status = 'U' and the code of the following process :

    :p15_updated_rows := :p15_updated_rows + 1;
    

    If you don't actually means "day" in the strict sense, and then change the status of process to include possible APEX$ ROW_STATUS 'C', 'U', and "D" values as needed. If you want to count all created, updated and deleted lines, do not add the condition to the process, but make sure the extended run is set to createand changed lines.

  • Table expanding: calculation of the difference in the value of the previous row

    Hello

    I'm a complete newbie to LiveCycle Designer (ES2) and created under the document with a table in full expansion.

    Shared files - Acrobat.com

    My goal is to make the friendly form by adding a calculation in the field "Twist" that calculates the difference of the current line to the previous row.

    I have no idea about Java Script, I'm afraid and also do not know if this is possible at all, so it's probably a bad idea after all.

    The reason for setting up as a table expansion is so that the form can be used for all 32 instances form would be used for (they all need different number of rows in total).

    The calculation will start in row 2 (Checklist.Table1), take the value of the entry in row 2 torsion and calculate the difference in the value of the twist entry in row 1.

    Then, in row 3, it calculates the difference between the value of the twist in the row 3 tier 2, etc.

    So subtract the value of the field in then with the value line onlinen-1 or something in that sense.

    Is there anyone at all who could help me with that at all?

    I would be very grateful for any advice you could give me.

    Thank you very much!

    Mathilda

    Hi Matilda,.

    Try this code;

    if (Row1.index > 0 && !Row1.resolveNode("NumericField4[0]").isNull)
    
     var prevTwist = Table1.resolveNode("Row1[" + (Row1.index - 1) + "].NumericField4[0]").rawValue
    
     var result = Math.abs(3000 / (Row1.resolveNode("NumericField4[0]").rawValue - prevTwist));
    
     this.rawValue = result;
    
     this.rawValue = "";
    

    Concerning

    Bruce

  • NUMBER of rows in the partition - shows null Calc.

    Hello world

    Hope all is well,

    Searched this forum and tried:

    Row_number partition...
    COUNTY partition...
    Partition of RANK...

    they all show null in the column of the calc.
    I rebuilt the query and displays always null when try the functions above in a Calc.
    The other Calc used in the query is NOT ANALYTICAL, if you wonder why you have trouble with this calc which is
    the only analytic function.

    Shows all the courses that are available for registration to students.
    Can be:

    DONKEYS 4000 06/01/10, 08/31/10 1
    DONKEYS 4000 09/01/10 11/31/10 2
    DONKEYS 4000 01/01/11 03/31/11 3

    DERM 4010 06/01/10, 08/31/10 1
    DERM 4010 09/01/10 11/31/10 2


    to assign a number to each line
    while I can set a condition for rowNumber = 1
    so that I can create a 'summary' of course query in the near future as this:
    to show just 1 row for each course

    DONKEYS 4000 06/01/10, 08/31/10 1
    DERM 4010 06/01/10, 08/31/10 1


    Your ideas would be appreciated, tx, sandra

    Hello
    If you like just the first line then you can do this by using the MIN/MAX functions (on the date).

    If you still want analytical functions created thanks for posting your calculations.
    Maybe it's that you already use aggregated values so that he can not aggregated twice.

    Tamir

  • How to determine the number of rows in the database and save the result to a local variable?

    Hello

    I'm a newbie in the use of TestStand, databases and SQL, and now I've met difficulties. I use TestStand 2014 (32 bit).

    I have a need to know the number of rows in a database and save that number in a local variable. I tried to practice using the database of the Types of step provided with TS. I tried to use the following in a SQL statement:

    Locals.NumberOfRows = ("SELECT COUNT (*) FROM TEST_TABLE")

    It returns an error: specified value is not the expected type. My goal is possible in this way, or I'm doing this completely wrong?

    -RautSa

    Thank you for your response, Norbert. I have a database of who wins new values at random, and sometimes I need the exact number of rows in this table.

    I managed to achieve my goal by using the SQL statement: "SELECT COUNT (*) as Rowcount OF TEST_TABLE", followed by a data GET operation, which records that number of lines in a local variable.

    -RautSa

  • number of rows in the table

    Hi master,

    I have a requirement. During the passage of a table, I need to get the number of rows in this table. Sometimes, when I spend 2 or more table names, I need to get the same count of result of lines. I got the below function. but it shows all the rows in the table. I want pariticular tabels only. How I can I get it.

    Select table_name, num_rows from all_tables where table_name in ('EMP', 'Department');  I tried.  I need to a procedure or function. who will pass the name of the table as a parameter and 1 or more than the name of a table if I pass, I need to display information from table name and number of lines.

    CREATE OR REPLACE

    TYPE t1_obj AS OBJECT)

    table-name VARCHAR2 (30),

    CNT NUMBER

    )

    /

    CREATE OR REPLACE

    TYPE t1_obj_tbl AS THE t1_obj TABLE

    /

    CREATE OR REPLACE

    FUNCTION (f1)

    p_schema_name VARCHAR2

    )

    RETURN t1_obj_tbl

    PIPELINED

    IS

    v_retval t1_obj: = t1_obj (null, null);

    BEGIN

    FOR v_rec IN (SELECT table_name FROM dba_tables where owner = upper (p_schema_name) and nvl (iot_type, 'X')! = "IOT_OVERFLOW") LOOP

    v_retval.table_name: = v_rec.table_name;

    RUN IMMEDIATELY "SELECT COUNT (*) FROM" | p_schema_name | '.' || v_rec.table_name

    IN v_retval.cnt;

    PIPE ROW (v_retval);

    END LOOP;

    RETURN;

    END;

    Select * from table (f1 ('scott'));

    The above function returns information from the table in SCOTT scheama. I need only perticular table info.

    Please notify.

    AR.

    Hi Sven,

    Front end people ask me the requirement. They wanted a proc or function as I want.

    Please help me.

    Concerning

    AR

  • Count the number of rows in a table (s)

    Hi all

    I have a TKT_PRIORITY_LK table that I want to count the number of rows returned by a priority level... say Low, Medium, High, critical. I want to be able to count how many of each created are they, instead returning ID instead, if making any sense... Can you please help with this.

    Example; Select count (*) in TKT_PRIORITY_LK

    PRIORITY group

    Kind regards

    Sandrine

    Try this

    Select a.PRIORITY, count (*) from TKT_PRIORITY_LK a, TKT_TICKET_MAIN b

    where a.id = b.PRIORITY_ID

    A.PRIORITY group

  • Error creating a salary. ORA-01422: exact fetch returns more than the requested number of rows in the hr_maintain_proposal_swi procedure insert_salary_proposal package

    Hi all

    We try to add new proposal for a salary of some employees from form August 1, 2015 (the Date of the beginning of employee)

    There is no existing salary proposal doesn't exist for these employees.

    We get below error.


    ORA-01422: exact fetch returns more than the requested number of rows in the hr_maintain_proposal_swi procedure insert_salary_proposal package


    Help, please.

    Thank you

    Tarun

    Hi John,.

    If it helps, take a look at the following note:

    ORA-01422 exact Fetch returns more than number of lines requested in Hr_maintain_proposal_swi (Doc ID 1673527.1)

    Kind regards

    Rajen

  • See the number of rows affected the performance of sqlplus to a sql file

    Hello

    It's just we have a sql file that contains a bunch of select/update/insert statements.

    I have a unix script that calls sqlplus on this sql file. However, at the exit I don't get the number of rows affected.

    Without adding any code in the input sql file, how can I change the code of sqlplus shell script to print the number of rows affected for each statement in the sql file?

    ${ORACLE_HOME}/bin/sqlplus -L >> ${LOG_FILE} 2>&1  << EOF
      ${ORAID}/${ORAPASS}@${ORAINS}
      whenever sqlerror exit sql.sqlcode;
      set echo on;
      set feedback off;
      set serveroutput on;
      @${SQL_FILE};
      exit;
    EOF
    RC=$?
    

    The SQL_FILE of entry content is:

    select 12 "col1" from dual;
    select 'abcd' "col2" from dual;
    select;
    select 13 'col3' from dual;
    

    The result of the race of sqlplus is (LOG_FILE):

    SQL*Plus: Release 11.2.0.2.0 Production on Fri Jun 6 14:28:00 2014
    
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    
    Enter user-name: 
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
    Data Mining and Real Application Testing options
    
    SQL> SQL> SQL> SQL> SQL> SQL> select 12 "col1" from dual;
    
          col1
    ----------
            12
    SQL> select 'abcd' "col2" from dual;
    
    col2
    ----
    abcd
    SQL> select;
    select
         *
    ERROR at line 1:
    ORA-00936: missing expression
    
    
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
    Data Mining and Real Application Testing options
    

    Thank you

    Srinivas - y.

    1. echo setting
    2. Set feedback off;

    use

    Set of feedback on

  • How can I get the number of rows in the table using Sunopsis API target in ODI 10 g?

    Hi guys,.

    In fact, I want to send an alert message as soon as the interface is run from a package. I've included alert OdiSendMail that sends an email once the interface is running.

    Could someone please tell how to get the number of rows inserted into the table the Sunopsis API target.

    I tried to use < % = odiRef.getNbRows () % >, but this has not worked for me. Since I am a beginner, could you please help out me

    This is my mail to send ODI format

    "The population of data managed to < % = odiRef.getSysDate () % >

    Total of lines in the target table is: < - need an API code-> "


    Kind regards

    Clinton

    Published by: LawrenceClinton on February 25, 2013 20:53

    Hello

    Create the project with details below variable

    Nom_de_variable: Total_Row_Count

    Type of variable: Variable discount

    Definition tab:
    Data type: digital
    Action: No persistent

    Refresh the tab:
    Schema: provide the schema of your repository to work and be

    SELECT log.nb_row
    THE journal of snp_step_log, snp_scen_step step
    WHERE log.nno = step.nno
    AND step.scen_no = (SELECT scen_no FROM snp_scen_step WHERE step_name='<%=odiRef.getPrevStepLog ('STEP_NAME") % > ')
    AND log.sess_no = '< % = odiRef.getSession ("SESS_NO") % >' code at low
    AND step.step_name = ' < % = odiRef.getPrevStepLog ("STEP_NAME") % > '

    Note: add this variable after the stage of interface in your package (after the interface anywhere you can place), you can add this variable before ODISendEmailNotification in your package

    call this varciable * #Total_Row_Count * in the Notification of ODISendEmail

    for example :

    Data has been fulfilled successfully in < % = odiRef.getSysDate () % >
    Total no of lines filled are: * #Total_Row_Count *

    it will work

    cordially,
    Phanikanth

    edited by: Phanikanth on February 28, 2013 01:13

    edited by: Phanikanth on February 28, 2013 01:14

Maybe you are looking for