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: Preferred way to check a record exists

Re: Preferred way to check a record exists

From: John Russell <netnews7_at_johnrussell.mailshell.com>
Date: Thu, 18 Sep 2003 03:54:40 GMT
Message-ID: <mcaimv8a0t7kphu6thdbkqlm7jda71h898@4ax.com>


On Wed, 17 Sep 2003 22:44:45 +1000, "David" <auto90059_at_hushmail.com> wrote:

>What's the preferred way to check whether a record actually exists in a
>table? If I wanted to check whether author is listed, is it naive to do
>something like this, or it better to catch the NO_DATA_FOUND exception?
>Maybe there's another approach altogether...
>
>SELECT COUNT (*)
> INTO v_count
> FROM People
> WHERE AddAuthor.address = Address
> AND author = Name;

I tend to use SELECT COUNT(*) ... WHERE ... AND ROWNUM < 2; which will stop looking as soon as the record is found. (Haven't analyzed the performance personally, but past discussion here suggests it can be more efficient.)

John

--
Photo gallery: http://www.pbase.com/john_russell/
Received on Wed Sep 17 2003 - 22:54:40 CDT

Original text of this message

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