You can't use SELECT COUNT(*) in Oracle because it will always give you the wrong count. For you to get an accurate count you will have to ANALYZE.

I am 100% sure this is not true.

ANALYZE collect statistics for the cost based optimizer and is used to improve (hopefully) the speed at which a query completes. It in no way impacts the results of the query... only the speed.

Update:

Just to confirm the above, I threw together a sample SQL script. Its output is below.

Update #2:

Now I think I know about what you are thinking -- the column 'num_rows' in the 'dba_tables' view is not populated until you analyze the table. This is not the same thing as doing a COUNT(*), but is similar.

--------------------------- ----- Test SQL Script ----- --------------------------- 1 SELECT version 2* FROM v$instance VERSION ----------------- 8.1.7.2.0 1* DROP TABLE oracle.bobtest DROP TABLE oracle.bobtest * ERROR at line 1: ORA-00942: table or view does not exist 1 CREATE TABLE oracle.bobtest 2* ( junk VARCHAR(1) ) Table created. 1 INSERT INTO oracle.bobtest 2* VALUES ( 'A' ) 1 row created. 1 row created. 1 row created. 1* COMMIT Commit complete. 1 SELECT COUNT(*) 2* FROM oracle.bobtest COUNT(*) ---------- 3 1 ANALYZE TABLE oracle.bobtest 2* COMPUTE STATISTICS Table analyzed. 1 SELECT COUNT(*) 2* FROM oracle.bobtest COUNT(*) ---------- 3 1 ANALYZE TABLE oracle.bobtest 2* DELETE STATISTICS Table analyzed. 1 SELECT COUNT(*) 2* FROM oracle.bobtest COUNT(*) ---------- 3 1 ANALYZE TABLE oracle.bobtest 2* ESTIMATE STATISTICS SAMPLE 20 PERCENT Table analyzed. 1 SELECT COUNT(*) 2* FROM oracle.bobtest COUNT(*) ---------- 3 1* DROP TABLE oracle.bobtest Table dropped.

In reply to Re: Re: Re: Handling conditions DBI in Oracle 8.1 by Rhose
in thread Handling conditions DBI in Oracle 8.1 by data67

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.