您可以在Oracle中创建一个将记录所有错误的触发器(或几乎所有错误 – NO_DATA_FOUND不被视为错误).在下面的示例中,架构中的任何错误都记录在TRACK_DETAIL表中(一行错误,下一行失败的SQL).您可以使用序列号,日期/时间等使其更复杂.
create table track_detail (val varchar2(4000));
create or replace procedure track (p_text IN VARCHAR2) IS
PRAGMA AUTONOMOUS_TRANSACTION;
begin
insert into track_detail(val)
values (p_text);
commit;
end;
.
/
create or replace TRIGGER log_err after servererror on schema
DECLARE
v_temp VARCHAR2(2000) := substr(dbms_utility.format_error_stack,1,2000);
v_num NUMBER;
v_sql_text ora_name_list_t;
begin
v_temp := translate(v_temp,'''','"');
track(v_temp);
v_num := ora_sql_txt(v_sql_text);
v_temp := null;
BEGIN
FOR i IN 1..v_num LOOP
v_temp := v_temp || v_sql_text(i);
END LOOP;
EXCEPTION
WHEN VALUE_ERROR THEN NULL;
END;
v_temp := translate(v_temp,''''||chr(0)||chr(10),'"');
track(v_temp);
end;
/
完成后,请记住删除(或禁用)触发器.