Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Simple question ...
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:02:41 CDT
![]() |
![]() |