DROP public synonym log_errors_tab
/
DROP TRIGGER log_errors_trig
/
DROP TABLE log_errors_tab PURGE
/
CREATE TABLE log_errors_tab
(
error VARCHAR2 (30),
timestamp DATE,
username VARCHAR2 (30),
osuser VARCHAR2 (30),
machine VARCHAR2 (100),
process VARCHAR2 (20),
program VARCHAR2 (100),
error_stack VARCHAR2 (3000),
captured_sql CLOB,
module VARCHAR2 (100),
action VARCHAR2 (100)
)
/
create public synonym log_errors_tab for sys.log_errors_tab
/
grant all on sys.log_errors_tab to public
/
CREATE OR REPLACE TRIGGER log_errors_trig
AFTER SERVERERROR
ON DATABASE
DECLARE
var_user VARCHAR2 (30);
var_osuser VARCHAR2 (30);
var_machine VARCHAR2 (100);
var_process VARCHAR2 (20);
var_program VARCHAR2 (100);
sql_text ora_name_list_t;
stmt CLOB;
n NUMBER;
v_module VARCHAR2 (100);
v_action VARCHAR2 (100);
BEGIN
BEGIN
SELECT SYS_CONTEXT('USERENV', 'AUTHENTICATED_IDENTITY'),--username,
osuser,
machine,
process,
program,
module,
action
INTO var_user,
var_osuser,
var_machine,
var_process,
var_program,
v_module,
v_action
FROM sys.v_$session
WHERE audsid = USERENV ('sessionid');
EXCEPTION
WHEN OTHERS
THEN
var_user := 'null';
END;
IF var_user not in ('SYSMAN','dbsnmp') THEN
BEGIN
n := ora_sql_txt (sql_text);
IF n > 1000
THEN
n := 1000;
END IF;
FOR i IN 1 .. n
LOOP
stmt := stmt || sql_text (i);
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
stmt := 'unable to get sql';
END;
INSERT INTO log_errors_tab
VALUES (DBMS_STANDARD.server_error (1),
SYSDATE,
var_user,
var_osuser,
var_machine,
var_process,
var_program,
DBMS_UTILITY.format_error_stack,
stmt,v_module,
v_action);
END IF;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
/
/
DROP TRIGGER log_errors_trig
/
DROP TABLE log_errors_tab PURGE
/
CREATE TABLE log_errors_tab
(
error VARCHAR2 (30),
timestamp DATE,
username VARCHAR2 (30),
osuser VARCHAR2 (30),
machine VARCHAR2 (100),
process VARCHAR2 (20),
program VARCHAR2 (100),
error_stack VARCHAR2 (3000),
captured_sql CLOB,
module VARCHAR2 (100),
action VARCHAR2 (100)
)
/
create public synonym log_errors_tab for sys.log_errors_tab
/
grant all on sys.log_errors_tab to public
/
CREATE OR REPLACE TRIGGER log_errors_trig
AFTER SERVERERROR
ON DATABASE
DECLARE
var_user VARCHAR2 (30);
var_osuser VARCHAR2 (30);
var_machine VARCHAR2 (100);
var_process VARCHAR2 (20);
var_program VARCHAR2 (100);
sql_text ora_name_list_t;
stmt CLOB;
n NUMBER;
v_module VARCHAR2 (100);
v_action VARCHAR2 (100);
BEGIN
BEGIN
SELECT SYS_CONTEXT('USERENV', 'AUTHENTICATED_IDENTITY'),--username,
osuser,
machine,
process,
program,
module,
action
INTO var_user,
var_osuser,
var_machine,
var_process,
var_program,
v_module,
v_action
FROM sys.v_$session
WHERE audsid = USERENV ('sessionid');
EXCEPTION
WHEN OTHERS
THEN
var_user := 'null';
END;
IF var_user not in ('SYSMAN','dbsnmp') THEN
BEGIN
n := ora_sql_txt (sql_text);
IF n > 1000
THEN
n := 1000;
END IF;
FOR i IN 1 .. n
LOOP
stmt := stmt || sql_text (i);
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
stmt := 'unable to get sql';
END;
INSERT INTO log_errors_tab
VALUES (DBMS_STANDARD.server_error (1),
SYSDATE,
var_user,
var_osuser,
var_machine,
var_process,
var_program,
DBMS_UTILITY.format_error_stack,
stmt,v_module,
v_action);
END IF;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
/
No comments:
Post a Comment