CREATE OR REPLACE PROCEDURE PSYS_SAVELOG(PROGRAM_NAME VARCHAR2,--过程名称 IS_SUCCEED VARCHAR2,--是否执行成功 Y|N EXECUTE_MSG CLOB,--过程执行信息 BEGIN_TIME TIMESTAMP --过程开始执行TIMESTAMP ) AS V_PROGRAM_NAME VARCHAR2(1000) := SUBSTRB(PROGRAM_NAME,1,1000); --过程名称 V_IS_SUCCEED CHAR(1) := SUBSTR(IS_SUCCEED,1); --过程执行成功表示 Y N V_BEGIN_TIME TIMESTAMP := BEGIN_TIME; PRAGMA AUTONOMOUS_TRANSACTION; --日志开启自治事务,不影响业务逻辑事务 /* 调用方式: 1.正常日志:PROC_SAVELOG(V_PROC_NAME,'Y','执行成功。。。',V_BEGIN_TIME); 2.异常日志:PROC_SAVELOG(V_PROC_NAME,'N',sqlERRM,V_BEGIN_TIME); */ BEGIN INSERT INTO PROGRAM_EXECUTE_LOG (PROGRAM_NAME,IS_SUCCEED,LOG_DATE,EXECUTE_MSG,--已改为CLOB TIME_CONSUMING,--EXECUTE_ORDER,EXECUTE_BEGINTIME,EXECUPSYS_SAVELOGTE_ENDTIME) VALUES (V_PROGRAM_NAME,V_IS_SUCCEED,SYSDATE,F_TIMESTAMP_DIFF(SYSTIMESTAMP,V_BEGIN_TIME),--PROGRAM_EXECUTE_LOG_SEQ.NEXTVAL,V_BEGIN_TIME,SYSTIMESTAMP); COMMIT; EXCEPTION WHEN OTHERS THEN ROLLBACK; END;
CREATE OR REPLACE PROCEDURE PSYS_PROCESS_ERRMSG(PROC_NAME VARCHAR2,--过程信息 EXE_MSG CLOB,--执行信息 ERR_MSG VARCHAR2,--错误信息 BEGIN_TIME TIMESTAMP,--过程开始执行TIMESTAMP RESULT OUT VARCHAR2) AS /*faith@2016.11.24用于处理异常信息,方便后续扩展 1.执行信息中添加ERR_MSG 2.执行记录日志过程 3.错误信息赋值给返回结果RESULT 调用方式: PROC_PROCESS_ERRMSG(V_PROC_NAME,V_EXE_MSG,V_ERR_MSG,RESULT); */ V_EXE_MSG CLOB := EXE_MSG; BEGIN RESULT := 'OK'; --如果错误信PSYS_PROCESS_ERRMSG息长度为0,返回OK IF LENGTH(ERR_MSG) = 0 OR ERR_MSG IS NULL THEN RETURN; END IF; DBMS_LOB.APPEND(V_EXE_MSG,ERR_MSG || CHR(10)); PSYS_SAVELOG(PROC_NAME,'I',BEGIN_TIME); ROLLBACK; RESULT := ERR_MSG; EXCEPTION WHEN OTHERS THEN RESULT := '处理异常信息发生错误!'; END;
-- Create table
create table PROGRAM_EXECUTE_LOG ( program_name VARCHAR2(1000),is_succeed CHAR(1),log_date DATE,execute_msg CLOB,time_consuming NUMBER,execute_order NUMBER,execute_begintime TIMESTAMP(6),execute_endtime TIMESTAMP(6),process_flag VARCHAR2(10) default 'N' ) tablespace YZB_DATA01 pctfree 10 initrans 1 maxtrans 255 storage ( initial 64 next 1 minextents 1 maxextents unlimited ); -- Add comments to the table comment on table PROGRAM_EXECUTE_LOG is '过程、函数、触发器执行性能日志'; -- Add comments to the columns comment on column PROGRAM_EXECUTE_LOG.execute_order is '流水号program_pfmc_log_seq'; comment on column PROGRAM_EXECUTE_LOG.process_flag is '处理标识(已处理Y,未处理N)';