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

Home -> Community -> Usenet -> c.d.o.server -> Re: Simple question ...

Re: Simple question ...

From: Ernest Morariu <ernest_at_gesora.com>
Date: Fri, 6 Aug 2004 16:50:24 +0200
Message-ID: <cf05rk$ibr$1@carabinieri.cs.interbusiness.it>


Daniel,

> DECLARE
>
> x VARCHAR2(20);
>
> BEGIN
> SELECT somecolumn
> INTO x
> FROM mytable
> WHERE 1=2;
>
> EXCEPTION
> WHEN NO_DATA_FOUND THEN
> x := 'No Data Found';
> END;
Thanks for the answer.
Doing this way means that my procedure is based on handling the exception. The exception should be executed just for *exceptional* situation, not for verifying the existence of the data ...

ernest

"Daniel Morgan" <damorgan_at_x.washington.edu> wrote in message news:1091800999.882128_at_yasure...
> Ernest Morariu wrote:
>
> > Hi All!
> >
> > The following command :
> >
> > SELECT myField INTO myVariable FROM myTable WHERE myCondition;
> >
> > generates an error if there is no record satisfying the condition
> > "myCondition".
> >
> > I would like to be able to do something like:
> >
> > SELECT myField INTO myVariable FROM myTable WHERE myCondition ;
> > if myVariable is null then
> > -- do something
> > else
> > -- do something else
> > end if ;
> >
> > Is there any way to do this without having to handle the exceptions ?
> >
> > I read somewhere that it not advisable to rely the code of the procedure
on
> > exceptions for getting common results.
> >
> > ernest
>
>
> DECLARE
>
> x VARCHAR2(20);
>
> BEGIN
> SELECT somecolumn
> INTO x
> FROM mytable
> WHERE 1=2;
>
> EXCEPTION
> WHEN NO_DATA_FOUND THEN
> x := 'No Data Found';
> END;
> /
>
> You should not be writing SELECT INTO, ever, without an exception
> handler.
>
> --
> Daniel A. Morgan
> University of Washington
> damorgan_at_x.washington.edu
> (replace 'x' with 'u' to respond)
>
Received on Fri Aug 06 2004 - 09:50:24 CDT

Original text of this message

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