How to catch exception for ORA-01427 in Oracle PL/SQL

 

Suppose you want to catch ORA-01427 in your exception in the PL/SQL, the following is the process


PROCEDURE my_proc(p_one VARCHAR2, p_err OUT VARCHAR2) IS

MORE_VALUES EXCEPTION;    -- here MORE_VALUES is the user defined exception
P
RAGMA EXCEPTION_INIT(MORE_VALUES -1427);


BEGIN


--- write your code here for the business logic.


EXCEPTION
    WHEN 
MORE_VALUES THEN
        p_err := 'Sub query returns more than one valuse';
        RAISE; -- re-raise the exception for the caller

END;

Post a Comment

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post