Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: count(*) vs. a cursor when determining the existing record on primary key

Re: count(*) vs. a cursor when determining the existing record on primary key

From: Ryan <rgaffuri_at_cox.net>
Date: Mon, 16 Jun 2003 20:57:09 GMT
Message-ID: <FaqHa.33820$Id7.451@news2.east.cox.net>


no

select pk
from tab
where pk = <value>

count, and group by employ sorting which is more expensive. this will just do a unique index scan. very fast.
"jgk" <javapda_at_yahoo.com> wrote in message news:6851e45e.0306161018.1e31fa7f_at_posting.google.com...
> If you have a table with a primary key and you want to determine if a
> particular primary key exists what is the fastest way to accomplish
> this?
>
> In Steve Feuerstein's great book "Oracle PL/SQL Best Practices"
> SQL-08: Use COUNT only when the actual number of occurrences is
> needed...he gives some case(s) where a cursor should be used instead
> of the count(*) function.
>
> If you have a table. The table has a primary key field. If you want
> to test for existence of a matching primary key is it better to use
> the COUNT function and see if there is a match > 0 (it would always be
> 1 or zero)...or should a cursor be used?
>
> Thanks,
>
> JGK
Received on Mon Jun 16 2003 - 15:57:09 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US