As the name suggest user defined exceptions are created by users. If you want to create your own exception you have to:
Example
I want to update all salaries of workers. But if there are no workers, raise an exception.
create or replace procedure update_salary
is
no_workers exception;
v_counter number := 0;
begin
select count(*) into v_counter from emp;
if v_counter = 0 then
raise no_workers;
else
update emp set salary = 3000;
end if;
exception
when no_workers then
raise_application_error(-20991,'We don''t have workers!');
end;
/
What does it mean raise
?
Exceptions are raised by database server automatically when there is a need, but if you want, you can raise explicitly any exception using raise
.
Procedure raise_application_error(error_number,error_message);