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: Connor McDonald <connor_mcdonald_at_yahoo.com>
Date: Fri, 19 Sep 2003 19:54:28 +0800
Message-ID: <3F6AEE74.7113@yahoo.com>


David 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;
> IF v_count = 1 THEN
> DBMS_OUTPUT.PUT_LINE (author || ' in ' || AddAuthor.address ||
> ' was found in the database, now registering as an author ...
> ');
> ELSE
> DBMS_OUTPUT.PUT_LINE (author || ' in ' || AddAuthor.address ||
> ' not found');

You simply answer the question that's been asked

select count(*)
from tab
where rownum = 1

or

select count(*)
from dual
where exists ( your_query_goes_here)

hth
connor Received on Fri Sep 19 2003 - 06:54:28 CDT

Original text of this message

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