Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Preferred way to check a record exists
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