Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: Question on Proper Use of EXISTS

Re: Question on Proper Use of EXISTS

From: Connor McDonald <connor_mcdonald_at_yahoo.com>
Date: Fri, 30 Mar 2001 19:48:05 +0800
Message-ID: <3AC47275.2987@yahoo.com>

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

Original text of this message

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