19. Handling custom exceptions

Handling
custom exceptions Both predefined exceptions and custom exceptions are related to oracle errors, and the occurrence of oracle errors will implicitly trigger the corresponding exceptions; while custom exceptions have nothing to do with oracle errors, they are created by developers for Exceptions defined by specific situations



? Please write a pl/sql block, receive an employee's number, and add 1000 yuan to the employee's salary, if the employee does not exist, please prompt


-- custom exception
create or replace procedure ex_test(sunNo number)
is
-- define a Exception
myexc exception;
begin --update
  user sal
  update kkkk set sal=sal+1000 where empno=sunNo;
  --sql%notfound this means no update
  --raise myexc; trigger myexc
  if sql%notfound then
    raise myexc;
    end if ;
    exception
      when myexc then
        dbms_output.put_line('No user has been updated!');
  end;


Displayed phenomenon:

SQL> exec ex_test(353);
No user has been updated!
PL/SQL procedure successfully completed

SQL> call ex_test(5345);
Method called

SQL> exec ex_test(535);
No users updated!
No users have been updated!
PL/SQL procedure successfully completedSummary


: If an exception is customized, if the exception is triggered by calling the program using call, but no message will be prompted, the message will be stored, and a prompt message will be issued when the program is called using exec.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327009879&siteId=291194637