Count the no.of rows without using count function

Hi,
How to count the no.of rows without using the count function?
Thanks,

they won't be 100% accurate. You're correct, Bluefrog, but the same goes for doing a count(*) (depending on the size of the table, ofcourse):
the table being queried might be under DML (deletes/inserts), and the next count(*) might give different results.
Both approaches will never be 100% accurate.
But simply selecting num_rows will be much much faster than doing a count(*).
Counting the number of rows always reminds me of this ongoing discussion, by the way:
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:127412348064#14136093079164 ;)
Usually knowing the number of records by approximatly is sufficient, imo. 1000000 or 1000007 records: I don't care, don't need to know that.
I've never needed to know the exact number of records in a table in my code, or been given a requirement that forced me to.

Similar Messages

  • Display the 3rd hieghest value without using rowid

    HI All,
    Can any one help me how to display the 3rd hieghest valuer without using a ROWID..
    Thanks
    Basava

    Frank, using ROWNUM = 1 instead of DISTINCT could be a bit faster:
    SQL> SET LINESIZE 132
    SQL> EXPLAIN PLAN FOR
      2  WITH got_r_num AS (
      3                     SELECT  DISTINCT sal,
      4                                      DENSE_RANK() OVER(ORDER BY sal DESC NULLS LAST) AS r_num
      5                       FROM  scott.emp
      6                    )
      7  SELECT  sal
      8    FROM  got_r_num
      9    WHERE r_num = 3
    10  /
    Explained.
    SQL> @?\RDBMS\ADMIN\UTLXPLS
    PLAN_TABLE_OUTPUT
    Plan hash value: 436395657
    | Id  | Operation                 | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT          |      |     9 |   234 |     5  (40)| 00:00:01 |
    |*  1 |  VIEW                     |      |     9 |   234 |     5  (40)| 00:00:01 |
    |   2 |   HASH UNIQUE             |      |     9 |    36 |     5  (40)| 00:00:01 |
    |*  3 |    WINDOW SORT PUSHED RANK|      |     9 |    36 |     5  (40)| 00:00:01 |
    |   4 |     TABLE ACCESS FULL     | EMP  |    14 |    56 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       1 - filter("R_NUM"=3)
       3 - filter(DENSE_RANK() OVER ( ORDER BY INTERNAL_FUNCTION("SAL") DESC
                  NULLS LAST)<=3)
    18 rows selected.
    SQL> EXPLAIN PLAN FOR
      2  WITH got_r_num AS (
      3                     SELECT  sal,
      4                             DENSE_RANK() OVER(ORDER BY sal DESC NULLS LAST) AS r_num
      5                       FROM  scott.emp
      6                    )
      7  SELECT  sal
      8    FROM  got_r_num
      9    WHERE r_num = 3
    10      AND ROWNUM = 1
    11  /
    Explained.
    SQL> @?\RDBMS\ADMIN\UTLXPLS
    PLAN_TABLE_OUTPUT
    Plan hash value: 21859616
    | Id  | Operation                 | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT          |      |     1 |    26 |     4  (25)| 00:00:01 |
    |*  1 |  COUNT STOPKEY            |      |       |       |            |          |
    |*  2 |   VIEW                    |      |    14 |   364 |     4  (25)| 00:00:01 |
    |*  3 |    WINDOW SORT PUSHED RANK|      |    14 |    56 |     4  (25)| 00:00:01 |
    |   4 |     TABLE ACCESS FULL     | EMP  |    14 |    56 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM=1)
       2 - filter("R_NUM"=3)
       3 - filter(DENSE_RANK() OVER ( ORDER BY INTERNAL_FUNCTION("SAL") DESC
                  NULLS LAST)<=3)
    19 rows selected.
    SQL> SY.

  • Select extra row without using UNION ALL in pl/sql

    Hi,
    Can anyone tell me how to select extra row without using UNION or UNION ALL in pl/sql. Actually I want to have my o/p of query as partitioned by designation and ordered by salary and than one extra row which will contain the highest salary in a particular salary. My table has first_name,emp_id,designation and salary column. And I wnt the o/p as.
    Mohinish,12212,SI,46000
    Ram,11212,SSI,47000
    Shyam,12133,SI,48000
    Rick,9898,SI,46000
    Rocky,12312,SSI,56000
    Sariq,23948,SI,43000
    Suman,12789,HR,49000
    Sampy,12780,SI,46000
    Parna,11111,HR,50000
    Now the o/p should be.
    Mohinish,12212,SI,46000
    Rick,9898,SI,46000
    Sariq,23948,SI,43000
    Shyam,12133,SI,48000
    Shyam,12133,SI,48000
    Ram,11212,SSI,47000
    Rocky,12312,SSI,56000
    Rocky,12312,SSI,56000
    Suman,12789,HR,49000
    Parna,11111,HR,50000
    Parna,11111,HR,50000
    Thanks in Advance

    You don't have to do a UNION or UNION ALL in PL/SQL but you would need to in SQL to get the desired output:
    with data_recs
    as (select 'Mohinish' first_name,12212 emp_id,'SI' designation,46000 salary from dual union
         select 'Ram',11212,'SSI',47000 from dual union
         select 'Shyam',12133,'SI',48000 from dual union
         select 'Rick',9898,'SI',46000 from dual union
         select 'Rocky',12312,'SSI',56000 from dual union
         select 'Sariq',23948,'SI',43000 from dual union
         select 'Suman',12789,'HR',49000 from dual union
         select 'Sampy',12780,'SI',46000 from dual union
         select 'Parna',11111,'HR',50000 from dual)
    select first_name, emp_id, designation, salary from data_recs union all
    select s.first_name, s.emp_id, s.designation, s.salary
      from (select first_name,
                   emp_id,
                   designation,
                   salary,
                   row_number() over (partition by designation order by salary desc) high_salary
              from data_recs
             order by designation, salary) s
    where s.high_salary = 1
    order by designation, salary;
    FIRST_NAME  EMP_ID DESIGNATION   SALARY
    Suman        12789 HR             49000
    Parna        11111 HR             50000
    Parna        11111 HR             50000
    Sariq        23948 SI             43000
    Rick          9898 SI             46000
    Mohinish     12212 SI             46000
    Sampy        12780 SI             46000
    Shyam        12133 SI             48000
    Shyam        12133 SI             48000
    Ram          11212 SSI            47000
    Rocky        12312 SSI            56000
    Rocky        12312 SSI            56000

  • Manually set up the essbase 11 client (without using the fusion installer)

    Hi All,
    is it possible to install the Essbase 11 client without using the Fusion Installer?
    I tryed to copy the "bin" and "locale" directory from an exisiting installation and set up the ARBORPATH environment variable - without success.
    Did I miss anything? Maybe some Registry entries? Or isn't it possible to set up the essbase client manually?
    Every answer would be appreciated.
    Cheers,
    Martin

    Hi John,
    thanks for the hint that the addin is also available for any version.
    I have an application which uses the C-API (essapinu.dll, essotlnu.dll, ...) and I want to test it with diffrent Essbase Client Versions against diffrent Essbase Servers.
    These are the (client) versions which I want to test:
    EssbaseRtc11110WindowsFiles
    EssbaseRtc11111WindowsFiles
    EssbaseRtc11112WindowsFiles
    EssbaseRtc11113WindowsFiles
    EssbaseRtc9203WindowsFiles
    EssbaseRtc9210WindowsFiles
    EssbaseRtc9301WindowsFiles
    EssbaseRtc9310WindowsFiles
    I hoped it would be enough to replace some directorys on a machine instead of starting a lot of installers.
    Cheers,
    Martin

  • I want to configure the 7330 motion controller without using MAX

    I am new to labview and I have a project where I have to configure the 7330 motion controller without using MAX. What do I need to do to get started doing so?
    Thanks for the help!
    nw2labview

    Hi,
    There are several VI's that are included with the motion driver for configuring your controller.  They are located on the function pallete under Vision and Motion>>Ni-Motion>>Axis Configuration.  Using these VI's you will be able to configure your axis.  But why don't you want to use MAX?  If you are new to LabVIEW I would suggest configuring and testing your motor in MAX first before you start programing.  Once you have it working there you may want to look at several of the examples such as Simple One-Axis Move.vi.  I hope this helps.
    GG

  • How to extract the mouse cursor image without using JNI

    I want to get the image of the mouse cursor of the system using java. The Robot class captures the screen only, but the mouse icon image is not the part of the screen, so it is not easily detected. But we can get the mouse cursor position using API, but how to get the exact image icon, without using JNI. I don't want to generate my own cursor at that position.

    I am building a Remote Desktop kinda app using java..... I want the screen of the remote comp to be viewed on my screen and generate events from my machine to the remote machine. So, I am capturing the screen images of the remote machine. But the cursor is not part of the screen object. i want to extract the cursor image icon from the remote machine to my machine and render the image.

  • HT2204 I have recently immigrated to the US but my apple ID is still stuck with my previous country. How do I change the country? Preferably without using a credit card

    I have recently immigrated to the US but my apple ID is still stuck with my previous country. How do I change the country? Preferably without using a credit cardI've only been here in the US 2 months and still have no US credit card.

    Your credit or debit card credentials must be associated with the same country where you reside.
    "Although you can browse the iTunes Store in any country without being signed in, you can only purchase content from the iTunes Store for your own country. This is enforced via the billing address associated with your credit card or other payment method that you use with the iTunes Store, rather than your actual geographic location."
    From here >  The Complete Guide to Using the iTunes Store | iLounge Article

  • Need to take rownum highest value without using grouping functions

    Hi
    I want to display highest value in the rownum column and customer details without using grouping functions like max or count
    this below query gives me all rownum values and customer details
    SELECT ROWNUM ROWNUM_1, CUSTOMER_NO, CUSTOMER_NAME, CUSTOMER_DOJ, CUSTOMER_MOBILENO FROM CUSTOMER;
    can any one help me.

    The above query won't work as it's missing "from" cluase in the inner select statement.
    And even if corrected it willl print rownum values thrice: value "1",max_rownum, max_rownum followed by customer details.
    Below is the simple query to retrieve max row_num along with the corresponding customer details.
    select * from (SELECT ROWNUM ROWNUM_1, CUSTOMER_NO, CUSTOMER_NAME, CUSTOMER_DOJ, CUSTOMER_MOBILENO FROM CUSTOMER order by rownum_1 desc) where rownum<=1 ;

  • Max value without using max() function

    Hi
    Is there any way to get the max value from a table without using MAX() function
    Thanks

    well if you think about it i'm sure you'll find a solution
    what does max(field) means, it simply is the value of the field where no other value of the same field that is > than this value exists.
    consider the following :
    table TAB(
    fld NUMBER(5));
    translate the logic and you'll have
    select a.fld from TAB a where NOT EXISTS(select b.fld from TAB b where b.fld>a.fld) and rownum=1;
    of course there are better ways i'm sure, you'll just have to figure'em out.

  • Alternate without using regexp_replace function

    SELECT
      REGEXP_REPLACE(phone_number,
                     '([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})',
                     '(\1) \2-\3') "REGEXP_REPLACE"
                     FROM employees;
    is there any alternate without using regexp_replace function.........

    Another way
    (eliminating instr function.. as your problem focusses on a fixed length)
    WITH t AS (SELECT '112.345.6789' str FROM DUAL),
         tt AS (SELECT REPLACE (str, '.') str FROM t)
    SELECT    '('
           || SUBSTR (str, 1, 3)
           || ') '
           || SUBSTR (str, 4, 3)
           || '-'
           || SUBSTR (str, 7)
      FROM tt;
    Cheers,
    Manik.

  • Hi, I have on my credit card monthly payments of fertilizer, and when I want to reveal to LR I get a reading indicating I should renew the subscription in order to use this function, alguine can help me ?? thx

    Hi, I have on my credit card monthly payments of fertilizer, and when I want to reveal to LR I get a reading indicating I should renew the subscription in order to use this function, alguine can help me ?? thx

    Thanks John, but this way is you get to this forum marinate options were
    not available
    2015-01-12 22:21 GMT-03:00 John T Smith <[email protected]>:
        Hi, I have on my credit card monthly payments of fertilizer, and when
    I want to reveal to LR I get a reading indicating I should renew the
    subscription in order to use this function, alguine can help me ?? thx
    created by John T Smith <https://forums.adobe.com/people/JohnTSmith> in *Adobe
    Creative Cloud* - View the full discussion
    <https://forums.adobe.com/message/7089860#7089860>

  • How to Delete duplicates rows without using rowid/distinct.

    How to delete duplicates rows present in a table without using rowid or even distinct.

    How about:
    SQL> SELECT * FROM t1;
             A          B
             1          2
             2          3
             1          2
             4          4
             4          4
             4          4
    SQL> DELETE FROM t1
      2  WHERE (a, b) IN (SELECT a, b FROM t1
      3                   GROUP BY a, b
      4                   HAVING COUNT(*) > 1) and
      5        rownum = 1;
    1 row deleted.
    SQL> /
    1 row deleted.
    SQL> /
    1 row deleted.
    SQL> /
    0 rows deleted.
    SQL> SELECT * FROM t1;
             A          B
             2          3
             1          2
             4          4Although, if I was asked a similar question with all those restrictions, my first response would be along the lines of: Is this question indicative of the way I will have to work if I join this company? If so, there is no point answering because I wouldn't touch this job with a ten foot pole.

  • How to manipulate data in multiple rows without using cursor??

    Hi all,
    I have a form in which there is a push button & 4 text fields.
    Push button : Process
    Text fields: Year, Month, Financial_To_Year, Financial_From_Date.
    In database , there are tables like, CUSTOMER_MASTER, FD_ACCOUNT_MASTER, FD_ACCOUNT_DTL, CUSTOMER_YEARLY_INTEREST, etc.
    In table FD_ACCOUNT_MASTER, there are columns, like CUST_CODE, FD_ACCT_NO, FD_AMOUNT, ACCT_OPEN_DT, ACCT_CLOSE_DATE, ACCT_TYPE, INTEREST_RATE, etc.
    There are thousands of records in the table.
    For Push button : Process , TRIGGER: When button pressed,
    I have to do all the process of FD for all the FD_ACCOUNTS at once. Process means i have to calculate Interest for all the accounts, calculate interest monthly, quarterly, yearly and make the FD_Accounts disable after the date of ACCT_CLOSE_DATE is reached, make the accounts renewed , etc all the process.
    But to do this process for multiple rows at once, we use cursor, but i don't want to use cursor as i feel its too tedious to do.
    Is there any other way , where i do process of multiple records at once without using cursor??
    Help me, Thank You.
    Oracle Forms Builder 6i.
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

    An Update statement certainly can update sets of data instead single row updates:
    UPDATE Statement
    if you can't do it in a single statement you can use bulk processing as well:
    PLSQL 101
    cheers

  • Delete internal table rows without using loop statement

    i have an internal table which consists of 100 records.
    i need to keep only first 5 records.
    without using the loop statement i need to delete the rest of the records. how can we achieve this result.
    i.e.  delete itab1 where  "recordno"  > 5.
    regards.
    ZG

    Hi,
    Delete itab [FROM idx1] [TO idx2] {Where (log_exp)]
    To delete several lines at once, you have to specify at least one of the additions FROM, TO, or WHERE. You can only use the additions FROM and TO with standard tables and sorted tables.
    Delete itab [FROM idx1]
    If you specify FROM, all the table rows from the table index idx1 onwards are included.
    Delete itab [TO idx2]
    If you specify TO, all the table rows from the table index idx2 onwards are included.
    PARAMETERS: p_carrid TYPE sflight-carrid,
                p_connid TYPE sflight-connid.
    DATA: BEGIN OF seats,
            fldate    TYPE sflight-fldate,
            seatsocc  TYPE sflight-seatsocc,
            seatsmax  TYPE sflight-seatsmax,
            seatsfree TYPE sflight-seatsocc,
          END OF seats.
    DATA seats_tab LIKE STANDARD TABLE OF seats.
    SELECT fldate seatsocc seatsmax
           FROM sflight
           INTO TABLE seats_tab
           WHERE carrid = p_carrid AND
                 connid = p_connid.
    LOOP AT seats_tab INTO seats.
      seats-seatsfree = seats-seatsmax - seats-seatsocc.
      MODIFY seats_tab INDEX sy-tabix FROM seats.
    ENDLOOP.
    ENDLOOP.
    SORT seats_tab BY seatsfree DESCENDING.
    DELETE seats_tab FROM 5.
    Thanks & Regards,
    ShreeMohan
    Edited by: ShreeMohan Pugalia on Jul 21, 2009 4:28 PM

  • Can I rewrite the following query without using Row_number() function ??!!

    Hello every one, can I rewrite the following query without using the 'ROW_NUMBER() OVER ' part.
    The query is supposed to pull out the records whose CODE is not NULL and has most
    recent date for UPDATE_DATE . The reason I wanted to do this is, When I embed this query
    in between many other queries along with JOINs, My oracle server is unable to execute. So, I thought
    its better to supplant 'ROW_NUMBER() OVER ' logic with something else and try it. .
    SELECT a.* FROM
    (SELECT b.*, ROW_NUMBER() OVER (PARTITION BY b.PIDM
    ORDER BY b.UPDATE_DATE DESC) AS Rno
    FROM
    SELECT *
    FROM SHYNCRO WHERE CODE IS NOT NULL
    )b
    )a
    WHERE a.Rno = 1

    Hi,
    You didn't write over 150 lines of code and then start testing it, did you?
    Don't.
    Take baby steps. Write as little as pssiblem test that. Debug and test again until you have something that does exactly what you want it to do.
    When you have somehting that works perfectly, take one baby step. Add a tiny amount of code, maybe 1 or 2 lines more, and test again.
    When you do get an error, or wrong results, you'll have a much better idea of where the problem is. also, you won't be building code on a flimsy foundation.
    If you need help, post the last working version and the new version with the error. Explain what you're trying to do in the new version.
    The error message indicates line 133. It looks like line 133 of your code is blank. Does your front end allow completely blank lines in the middle of a query? SQL*Plus doesn't by default; you have to say
    SET  SQLBLANKLINES  ONto have a completely blank line in SQL*Plus. (However, lines containing nothing but at commnet are always allowed.)
    You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as indented code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    The 4 people who posted small code fragments for you to read all did this.  It would be so much easier for people to read your humongeous query if it were formatted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • IOS6 WiFi Problems, please help!

    I have the iPhone 4 and updated to the iOS6 today. Well after updating my wifi will not work.. The thing is I am at college and the wifi here you have to go to Safari and type in username and password everytime. Well when I go to do so, it will not l

  • There seems to be an issue with opendns free servers

    ''(Locked. Not a support question. See bold text for reasons of locking -m)'' This is more of a "I found it" than a question as this seems to be an issue with the opendns free DNS servers related to certain torrent sites and the duckduckgo search eng

  • Creating a job

    hi , sql developer 4.0.2 i want to run a batch file (.bat) every day , so i did that " scheduler > job(wizard) > job type(executable) > selected the .bat file > when to execute a job(Repeating) > clicked the edit button for " repeat interval " > in t

  • Recommended Security Suite for Firefox 25. Using Mcafee Security Center ver 12.8, wondering if I should change to Bitdefender or Kaspersky? Any suggestion

    Have 2 Win 8 machines, running Firefox 25 and one lap top with Win 7. All three are using Mcafee Security Suite ver 12.8 with Anti Virus 16.8. The subscription runs out in February 2014. I would like to make a change and am concerned about compatibil

  • Iphone, Ipad and 2 x Ipod

    I currently have my Iphone and Ipad setup on my mac itunes. The wife has her iphone on her PC with Itunes Whenever they download, we use my account so I have to enter my credentials. I do this because I like to keep track on things and I don't want t