Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Preferred way to check a record exists
"David" <auto90059_at_hushmail.com> wrote in message news:3f68573e$0$10355$afc38c87_at_news.optusnet.com.au...
> 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');
Pure SQL?
PL/SQL?
NO_DATA_FOUND sounds good to me.
Although this should also work:
select
nvl((select 'Y' from People where ....),'N')
into l_var
from dual;
if (l_var = 'Y') then
. . .
-- Cheers Nuno Souto wizofoz2k_at_yahoo.com.au.nospamReceived on Wed Sep 17 2003 - 08:12:27 CDT