Re: EXIST, NOT EXIST problem

From: JJ <jj123_at_yahoo.com>
Date: Wed, 20 Jun 2001 07:57:20 -0400
Message-ID: <9gq228$78u8_at_kcweb01.netnews.att.com>


"Enrico Brighi" <ebrighi_at_cineca.it> wrote in message news:9gphk3$2o5$1_at_newsfeed.cineca.it...
> Hi,
> how can i translate this pseudocode in PL/SQL?
>
> if EXISTS(select ......) then
>
> elsif NOT EXISTS(select....) then
>
> end if;
>
> I think one way is the sequent:
>
> Condition 1
>
> select ... into var1 where ....
>
> Condition 2
>
> select ... into var2 where.....
>
> and so the code is:
>
> if (var1 <> 0 ) then
>
> elsif (var2 = 0) the
>
> end if;
>
> ...but it's a problem, because the select fails if no return a value INTO
> the variable!!
>
> How can i do??
>
> Thank
> enrico brighi
>
If i understood your question correctly....

Use the exception "when no_data_found"

Sample code:
begin
declare var1 varchar(2);
begin
select 'b' into var1
from dual
where exists (select dummy from dual where 1 =2); exception
when no_data_found then
if var1 is null then
dbms_output.put_line('var1 is null');
end if;
end;
end;

HTH
JJ Received on Wed Jun 20 2001 - 13:57:20 CEST

Original text of this message