Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Q: To check a record's existence in a table, FAST!
In article <335E273E.3B24_at_internex.com.au>, Jonas Plumecocq
<jp_at_internex.com.au> writes
[severe snip]
> The row count is immaterial to me, i just want to know if any record
>
> exists or not. The count(*) used in second option is used just to
> facilitate the checking for value return (0 or 1) in a SQL statement
> .
> like
>
> select count(*) into nCount from table where x='aa' and rownum=1;
> if nCount = 1 then
> ....
> end if;
This is fine - when using the rownum pseudo-column Oracle assigns a number with each row returned using a COUNT function (not to be confused with 'count(*)'). If the rownum is specified in the where clause, it will use a COUNT STOP - this will end the query when the count exceeds that specified.
I think that I'd prefer to see an IF %FOUND or EXCEPTION defined the above block to cater more clearly for when the record does not exist.
Andy
Andy Hardy. PGP key available on request