Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> How To Trap No Rows Returned From Select Statement
Hi all.
I am having trouble working out how to trap whether my select statement returned any rows - This seems to be more difficult with implicit cursors, and I been able to figure it out :-).
I would like to trap for the user entering the wrong name, and displaying an appropriate message as shown, hopefully:
The procedure has just enough code to demonstrate the problem:
CREATE OR REPLACE PROCEDURE PrintMethod ( MethodName VARCHAR2 ) IS
MyException EXCEPTION;
CURSOR MyCursor IS SELECT * FROM USER_SOURCE
WHERE NAME = UPPER( TRIM( MethodName ) );
BEGIN
DBMS_OUTPUT.PUT_LINE( 'Line ' || MyCursor%ROWCOUNT || ': ' || MyRow.TEXT );
END LOOP;
EXCEPTION
WHEN MyException THEN
DBMS_OUTPUT.PUT_LINE( 'Oop''s - That name could not be found ... ' );
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE( 'Oop''s - Unknown Error Raised ... ' );
END;
/
...but, when the name is not found, all I get is the message: PL/SQL procedure successfully completed.
I would like to have my exception handler invoked, so I can display my message, and if possible, also remove the "PL/SQL procedure successfully completed." message from following it.
For Example:
SQL> EXEC PrintMethod( 'GetNumber' );
Why does SQL%NOTFOUND not return true ?, and how do I fix it ?
Any help appreciated.
Thanks.
Chris Val
Received on Mon Jul 05 2004 - 20:47:56 CDT