Home » SQL & PL/SQL » SQL & PL/SQL » SIMPLE QUESTION
SIMPLE QUESTION [message #3382] Tue, 24 September 2002 09:42 Go to next message
HIT1
Messages: 4
Registered: September 2002
Junior Member
in pl/sql block if i write one query
as

declare
begin
select * from emp where empno=9999;
if sql%notfound then
dbms_output.put_line('error message in sql cursor');
end if;

exception when no_data_found then
dbms_output.put_line('error message in exception');
end exception;
end;

may be syntax was somewhat wrong but question is like this.

what will be output????
Re: SIMPLE QUESTION [message #3384 is a reply to message #3382] Tue, 24 September 2002 10:07 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
In PL/SQL, you must always select INTO a variable. Also, a SQL%NOTFOUND statement is not relevent with a SELECT INTO. If a single row is not returned, either a NO_DATA_FOUND or a TOO_MANY_ROWS exception will be raised.

declare
  v_empno  emp.empno%type;
begin
  select empno
    into v_empno
    from emp
   where empno = 9999;
exception
  when no_data_found then
    dbms_output.put_line(...);
end;
Previous Topic: Re: select statement question
Next Topic: RECORD parameter
Goto Forum:
  


Current Time: Wed May 08 05:01:23 CDT 2024