Records a error in the error logging table. : Utility trigger « Trigger « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » Trigger » Utility trigger 
28. 20. 3. Records a error in the error logging table.
SQL>
SQL>
SQL> CREATE SEQUENCE system_error_id NOCACHE;

Sequence created.

SQL>
SQL> CREATE TABLE system_errors
  2     (system_error_id  NUMBER(10,0), package_name  VARCHAR2(50),
  3      procedure_name  VARCHAR2(50), execution_location  varchar2(20),
  4      oracle_error_text  VARCHAR2(200),
  5      additional_information  VARCHAR2(2000),
  6      call_stack   VARCHAR2(2000), error_stack  VARCHAR2(2000),
  7      insert_time  DATE, insert_user  VARCHAR2(30));

Table created.

SQL>
SQL> COMMENT ON TABLE system_errors IS
  2     'Errors generated by stored packages.';

Comment created.

SQL> COMMENT ON COLUMN system_errors.system_error_id IS
  2     'The system-wide ID to identify a system error. Useful for
  3      determining the order in which errors were encountered and
  4      logged.';

Comment created.

SQL> COMMENT ON COLUMN system_errors.package_name IS 'Thpackage name.';

Comment created.

SQL> COMMENT ON COLUMN system_errors.procedure_name IS 'Thprocedure/function name.';

Comment created.

SQL> COMMENT ON COLUMN system_errors.execution_location IS 'A reference to a location in the executing code.';

Comment created.

SQL> COMMENT ON COLUMN system_errors.oracle_error_text IS 'The text of the Oracle error message.';

Comment created.

SQL> COMMENT ON COLUMN system_errors.additional_information IS 'Any pertinent information the developer may be trapping by the error handler.';

Comment created.

SQL> COMMENT ON COLUMN system_errors.call_stack IS 'The call stack at the time of the error.';

Comment created.

SQL> COMMENT ON COLUMN system_errors.error_stack IS 'The error stack at the time of the error.';

Comment created.

SQL> COMMENT ON COLUMN system_errors.insert_time IS 'The date and time of record insertion.';

Comment created.

SQL> COMMENT ON COLUMN system_errors.insert_user IS 'The user inserting the record.';

Comment created.

SQL>
SQL> CREATE OR REPLACE PROCEDURE log_error
  2     (p_package_txt   VARCHAR2 DEFAULT 'UNKNOWN',
  3     p_procedure_txt VARCHAR2 DEFAULT 'UNKNOWN',
  4     p_location_txt  VARCHAR2 DEFAULT 'UNKNOWN',
  5     p_error_txt     VARCHAR2 DEFAULT 'UNKNOWN',
  6     p_text_txt      VARCHAR2 DEFAULT 'NONE',
  7     p_commit_bln    BOOLEAN  DEFAULT TRUE,
  8     p_user_txt      VARCHAR2 DEFAULT USER,
  9     p_time_date     DATE     DEFAULT SYSDATEIS
 10     lv_call_stack_txt VARCHAR2(2000);
 11     lv_error_stack_txt VARCHAR2(2000);
 12     pu_failure_excep EXCEPTION;
 13     PRAGMA EXCEPTION_INIT (pu_failure_excep, -20000);
 14  BEGIN
 15     lv_call_stack_txt := SUBSTR(DBMS_UTILITY.FORMAT_CALL_STACK, 12000);
 16     lv_error_stack_txt := SUBSTR(DBMS_UTILITY.FORMAT_ERROR_STACK, 12000);
 17     INSERT INTO system_errors (system_error_id, package_name, procedure_name,
 18         execution_location, oracle_error_text, additional_information,
 19         call_stack, error_stack, insert_time, insert_user)
 20     VALUES (system_error_id.NEXTVAL, SUBSTR(p_package_txt, 150),
 21         SUBSTR(p_procedure_txt, 150),
 22         SUBSTR(p_location_txt, 120), SUBSTR(p_error_txt, 1200),
 23         SUBSTR(p_text_txt, 12000), lv_call_stack_txt,
 24         lv_error_stack_txt, p_time_date, p_user_txt);
 25     IF p_commit_bln THEN
 26        COMMIT;
 27      END IF;
 28  EXCEPTION
 29     WHEN OTHERS THEN
 30        RAISE pu_failure_excep;
 31  END log_error;
 32  /

Procedure created.

SQL>
SQL> drop sequence system_error_id;

Sequence dropped.

SQL>
SQL>
SQL> drop table system_errors;

Table dropped.
28. 20. Utility trigger
28. 20. 1. Use trigger to keep data consistency
28. 20. 2. A trigger prevents updates after business hours
28. 20. 3. Records a error in the error logging table.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.