Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: Question on Proper Use of EXISTS
Ray Vonhollen wrote:
>
> I'm getting contrary information between earlier Oracle documentation
> on the proper use of the EXISTS condition and current useage in Oracle
> 8i. What I'm simply
> trying to accomplish is to see if a record(s) exists within a Delete
> After Trigger, and then perform some action if it does. The target
> table may contain many instances, but I just need to return a True or
> False if it EXISTS at all.
>
> (Example, Sybase or SQL)
>
> If EXISTS (Select 1 from Mytable where Mytable.ID = :OLD.ID) Then
> ..
> ..
> END IF;
>
> I've tried every combination including embedding the EXISTS after the
> Where clause, all to no avail.
>
> IF (Select DISTINCT 1 From MyTable Where Exists (Select DISTINCT 1
> from MyTable Where (MyTable.ID = :OLD.ID))) Then
> END IF;
>
> Can someone supply me with the proper syntax in order to accomplish
> the above?
>
> Much appreciation for any help.
>
> R-
select 1 into flag from dual
where exists ( your query )
If you get '1', its there, if you get nothing (ie no data found) it aint...
hth
connor
-- =========================================== Connor McDonald http://www.oracledba.co.uk (mirrored at http://www.oradba.freeserve.co.uk) "Some days you're the pigeon, some days you're the statue"Received on Fri Mar 30 2001 - 05:48:05 CST
![]() |
![]() |