标签:
WHO_AM_I()
CREATE OR REPLACE FUNCTION WHO_AM_I RETURN VARCHAR2 IS l_owner varchar2(30); l_name varchar2(30); l_lineno number; l_type varchar2(30); BEGIN who_called_me( l_owner, l_name, l_lineno, l_type ); RETURN l_name; END;
WHO_CALLED_ME
CREATE OR REPLACE PROCEDURE WHO_CALLED_ME (owner out varchar2, name out varchar2, lineno out number, caller_t out varchar2) as call_stack varchar2(4096) default dbms_utility.format_call_stack; n number; pos NUMBER; found_stack BOOLEAN default FALSE; line varchar2(255); cnt number := 0; begin --dbms_output.put_line(call_stack); loop n := instr(call_stack, chr(10)); exit when(cnt = 3 or n is NULL or n = 0); -- line := substr(call_stack, 1, n - 1); --dbms_output.put_line(‘line:‘||substrb(line,1,255)); call_stack := substr(call_stack, n + 1); -- if (NOT found_stack) then if (line like ‘%handle%number%name%‘) then found_stack := TRUE; end if; else cnt := cnt + 1; -- cnt = 1 is ME -- cnt = 2 is MY Caller -- cnt = 3 is Their Caller if (cnt = 3) then --lineno := to_number(substr( line, 13, 6 )); --QianDS Add 2005-6-16 20:13 pos := INSTRB(line, ‘ ‘, 1); lineno := to_number(substr(line, pos, 10)); -------------------------------/ --line := substr( line, 21 ); --QianDS Add 2005-6-16 20:13 line := substr(line, pos + 12); -------------------------------/ if (line like ‘pr%‘) then n := length(‘procedure ‘); elsif (line like ‘fun%‘) then n := length(‘function ‘); elsif (line like ‘package body%‘) then n := length(‘package body ‘); elsif (line like ‘pack%‘) then n := length(‘package ‘); elsif (line like ‘anonymous%‘) then n := length(‘anonymous block ‘); else n := null; end if; if (n is not null) then caller_t := ltrim(rtrim(upper(substr(line, 1, n - 1)))); else caller_t := ‘TRIGGER‘; end if; line := substr(line, nvl(n, 1)); n := instr(line, ‘.‘); owner := ltrim(rtrim(substr(line, 1, n - 1))); name := ltrim(rtrim(substr(line, n + 1))); end if; end if; end loop; end;
P_SYS_PROCEDURE
CREATE OR REPLACE PROCEDURE P_SYS_PROCEDURE ( v_pro_id IN VARCHAR2, v_pro_type IN VARCHAR2, v_cycle IN VARCHAR2,--处理周期 v_channel IN NUMBER,--通道号 v_tag IN NUMBER,--0,过程开始1,过程结束 v_execcycle OUT VARCHAR2, v_result_tag OUT CHAR ) ----------------------------------------------------------------------- -- PROCEDURE: P_SYS_PROCEDURE -- Description: 填写过程执行日志 -- Author: linage_stat -- Date: 2005/04/13 -- Editor: EditPlus 2.11 ----------------------------------------------------------------------- IS iv_err_code VARCHAR2(20); iv_err_log VARCHAR2(2000); iv_execpro_id NUMBER; BEGIN v_result_tag := ‘N‘; --处理过程执行周期 IF v_cycle IS NULL THEN IF v_pro_type IN (‘1‘,‘2‘) THEN v_execcycle := ENVINFO.PREVIOUS_DAY; ELSE v_execcycle := ENVINFO.PREVIOUS_MONTH; END IF; ELSE IF v_pro_type IN (‘1‘,‘2‘) THEN v_execcycle := to_char(to_date(v_cycle,‘yyyymmdd‘),‘yyyymmdd‘); ELSE v_execcycle := to_char(to_date(v_cycle,‘yyyymm‘),‘yyyymm‘); END IF; END IF; --判断是否为过程开始执行 IF v_tag = 0 THEN INSERT INTO tf_s_pro_log (EXECPRO_ID,SESSION_ID,SESSION_USER,PRO_ID,EXEC_CYCLE,CHANNEL_NO,BEGIN_DATE) SELECT f_sys_getseqid(),ENVINFO.SESSIONID,ENVINFO.SESSION_USER,v_pro_id,v_execcycle,v_channel,SYSDATE FROM DUAL; COMMIT; v_result_tag := ‘Y‘; ELSIF v_tag = 1 THEN SELECT MAX(execpro_id) INTO iv_execpro_id FROM tf_s_pro_log WHERE pro_id = v_pro_id AND end_date IS NULL AND nvl(channel_no,0) = nvl(v_channel,0) AND exec_cycle = v_execcycle; v_result_tag := ‘Y‘; iv_err_code := ‘ORA-0000‘; UPDATE tf_s_pro_log SET (end_date,result_tag,err_code,err_log) = (SELECT SYSDATE,v_result_tag,iv_err_code,‘‘ FROM DUAL) WHERE execpro_id = iv_execpro_id; COMMIT; ELSE v_result_tag := ‘N‘; END IF; EXCEPTION WHEN OTHERS THEN iv_err_log := SQLERRM; iv_err_code := SUBSTR(SQLERRM,1,instr(SQLERRM,‘:‘)-1); INSERT INTO tf_s_pro_log (EXECPRO_ID,SESSION_ID,SESSION_USER,PRO_ID,EXEC_CYCLE,CHANNEL_NO,BEGIN_DATE,END_DATE,RESULT_TAG,ERR_CODE,ERR_LOG) SELECT f_sys_getseqid(),ENVINFO.SESSIONID,ENVINFO.SESSION_USER,v_pro_id,v_cycle,v_channel,SYSDATE,SYSDATE,‘N‘,iv_err_code,iv_err_log FROM DUAL; COMMIT; END;
标签:
原文地址:http://my.oschina.net/liyonglee/blog/512177