Home » SQL & PL/SQL » SQL & PL/SQL » Exceptio "e_no_deptno" never gets executed????
Exceptio "e_no_deptno" never gets executed???? [message #38016] Wed, 13 March 2002 12:27 Go to next message
Sid
Messages: 38
Registered: May 1999
Member
The exception for "e_no_deptno" is not raised.
If I enter a valid deptno for example 10 - 50 then it prints
"deptno exist in deptt table"

However when I enter a deptno that does not occur in the table no excpeiton is raised, but PL/SQL code is executed successfully. The line

"error number does not exist"

Never gets printed.

Why?

ACCEPT p_number PROMPT 'Please enter department number: '

DECLARE

e_no_deptno EXCEPTION;

v_deptno deptt.deptno%TYPE := TO_NUMBER(&p_number);

CURSOR c_deptno is SELECT DEPTNO FROM DEPTT;
BEGIN
For i IN c_deptno loop
IF i.deptno = v_deptno THEN
DBMS_OUTPUT.PUT_LINE('deptno exist in deptt table');
ELSIF c_deptno%NOTFOUND THEN
RAISE e_no_deptno;
END IF;
END LOOP;

EXCEPTION
WHEN e_no_deptno THEN
DBMS_OUTPUT.PUT_LINE('error number does not exist in deptt table');

END;
/
Re: Exceptio "e_no_deptno" never gets executed???? [message #38017 is a reply to message #38016] Wed, 13 March 2002 12:40 Go to previous message
raji
Messages: 30
Registered: February 2002
Member
Remove %notfound and just check for if-else condition.

ACCEPT p_number PROMPT 'Please enter department number: '

DECLARE

e_no_deptno EXCEPTION;

v_deptno deptt.deptno%TYPE := TO_NUMBER(&p_number);

CURSOR c_deptno is SELECT DEPTNO FROM DEPTT;
BEGIN
For i IN c_deptno loop
IF i.deptno = v_deptno THEN
DBMS_OUTPUT.PUT_LINE('deptno exist in deptt table');
ELSE
RAISE e_no_deptno;
END IF;
END LOOP;

EXCEPTION
WHEN e_no_deptno THEN
DBMS_OUTPUT.PUT_LINE('error number does not exist in deptt table');

END;
/
Previous Topic: ORA-4091 Mutating Tables
Next Topic: order by procedure parameter
Goto Forum:
  


Current Time: Fri Apr 26 02:30:44 CDT 2024