Oracle PL/SQL/PL SQL/Errors Table

Материал из SQL эксперт
Перейти к: навигация, поиск

Insert into Errors table: sqlcode, sqlerrm

SQL>
SQL> -- insert into Errors table
SQL>
SQL> DECLARE
  2    v_code NUMBER;
  3    v_message VARCHAR2(255);
  4    v_num1  NUMBER := &first_number;
  5    v_num2  NUMBER := &second_number;
  6    myResult NUMBER;
  7  BEGIN
  8    myResult := v_num1/v_num2;
  9    DBMS_OUTPUT.PUT_LINE(myResult);
 10  EXCEPTION
 11    WHEN OTHERS THEN
 12      v_code := SQLCODE;
 13      v_message := SUBSTR(SQLERRM,1,255);
 14      DBMS_OUTPUT.PUT_LINE("Some error occurred");
 15      INSERT INTO Errors(UserName, Code, Message) VALUES(USER, v_code, v_message);
 16  END;
 17
 18  /
Enter value for first_number: 1
old   4:   v_num1  NUMBER := &first_number;
new   4:   v_num1  NUMBER := 1;
Enter value for second_number: 2
old   5:   v_num2  NUMBER := &second_number;
new   5:   v_num2  NUMBER := 2;