一个完整的示例包体
来源:互联网 发布:淘宝收藏店铺链接 编辑:程序博客网 时间:2024/06/07 04:00
create or replace package body fxq_risk_pkg is--*********************************************************************************--功能说明:-- 日志过程--参数说明:-- p_id_fxq_log 日志ID-- p_proc_name 过程名 -- p_err_line 异常行数-- p_err_code 错误代码 异常时获取错误代码 正常时 S开始 E结束 sqlerrm 具体异常信息-- p_err_msg 错误信息-- p_user 创建人 --创建说明:创建者 创建日期-- xxx 2015-04-27--修改历史:修改者 修改日期 修改原因(简要说明)-- 暂无 暂无 暂无--*********************************************************************************procedure proc_log(p_id_fxq_log varchar2, p_proc_name varchar2, p_err_line varchar2, p_err_code varchar2, p_err_msg varchar2, p_user varchar2 )is pragma autonomous_transaction; v_err_msg varchar2(4000);beginv_err_msg := p_err_msg; if p_err_code = 'E' then --S 表示程序开始 不用计算耗时 select to_char((sysdate - created_date) * 24 * 60, 'fm9999999990.00') into v_err_msg from fxq_log where id_fxq_log = p_id_fxq_log; v_err_msg := substrb('耗时:'||v_err_msg||'分, '||p_err_msg, 1, 4000); end if; merge into fxq_log ausing (select count(1) cnt from fxq_log where id_fxq_log = p_id_fxq_log) b on (b.cnt > 0) when matched then update set err_line = p_err_line , err_code = p_err_code , err_msg = v_err_msg , updated_by = nvl(p_user, user) , updated_date = sysdate where id_fxq_log = p_id_fxq_log when not matched then insert (id_fxq_log , proc_name , err_line , err_code , err_msg , created_by , created_date )values( nvl(p_id_fxq_log, sys_guid()) , p_proc_name , p_err_line , p_err_code , v_err_msg , nvl(p_user, user) , sysdate ); commit;end proc_log;--*********************************************************************************--功能说明:-- 写入状态--参数说明:-- p_status_sign状态标识(Y/N)-- p_date_num 数据量 -- p_data_date 数据日期 -- p_user 用户名--创建说明:创建者 创建日期-- <span style="font-family: Arial, Helvetica, sans-serif;">xxx </span><span style="font-family: Arial, Helvetica, sans-serif;">2015-04-27</span>--修改历史:修改者 修改日期 修改原因(简要说明)-- 暂无 暂无 暂无--*********************************************************************************procedure proc_status(p_status_sign varchar2, p_date_num number , p_data_date date , p_user varchar2 )isbegin insert into fxq_status(id_fxq_status , status_sign , data_num , data_date , created_by , created_date , updated_by , updated_date )values( sys_guid() , p_status_sign , p_date_num , trunc(p_data_date) , nvl(p_user, user) , sysdate , nvl(p_user, user) , sysdate );--commit;end proc_status;--*********************************************************************************--功能说明:-- 从结果表(amlm_ars_company_result)把复核通过的数据写入到接口表(amlm_ars_company_result_inf)--参数说明:-- p_user 用户-- p_sysdate 日期(处理哪一天的数据就传哪一天日期)-- p_msg Y:正常 返回其它值为异常--创建说明:创建者 创建日期-- xxx 2015-04-27--修改历史:修改者 修改日期 修改原因(简要说明)-- 暂无 暂无 暂无--*********************************************************************************procedure proc_company_result_insert_inf(p_user varchar2, p_sysdate date , p_msg out varchar2 )is v_proc varchar2(90) := 'fxq_risk_pkg.proc_company_result_insert_inf'; v_count number := 0; v_guid varchar2(32); v_sysdate date; v_date_1 date; --获取日期 v_date_1d varchar2(10); --获取日期的天数做为分区标识 k number := 0; v_numnumber := 0; v_sql varchar2(4000); type t_id_amlm_ars_company_result is table of amlm_ars_company_result_inf.id_amlm_ars_company_result %type;type t_batch_seq is table of amlm_ars_company_result_inf.batch_seq %type;type t_cust_seq is table of amlm_ars_company_result_inf.cust_seq %type;type t_group_seq is table of amlm_ars_company_result_inf.group_seq %type;type t_series_code is table of amlm_ars_company_result_inf.series_code %type;type t_company_client_id is table of amlm_ars_company_result_inf.company_client_id %type;type t_company_risk_level is table of amlm_ars_company_result_inf.company_risk_level %type;type t_client_worth is table of amlm_ars_company_result_inf.client_worth %type;type t_point_template_score is table of amlm_ars_company_result_inf.point_template_score %type;type t_point_template_id is table of amlm_ars_company_result_inf.point_template_id %type;type t_formula_id is table of amlm_ars_company_result_inf.formula_id %type;type t_attribute_id is table of amlm_ars_company_result_inf.attribute_id %type;type t_next_risk_date is table of amlm_ars_company_result_inf.next_risk_date %type;type t_client_type is table of amlm_ars_company_result_inf.client_type %type;type t_status is table of amlm_ars_company_result_inf.status %type;type t_group_risk_level is table of amlm_ars_company_result_inf.group_risk_level %type;type t_created_date is table of amlm_ars_company_result_inf.created_date %type;type t_created_by is table of amlm_ars_company_result_inf.created_by %type;type t_updated_date is table of amlm_ars_company_result_inf.updated_date %type;type t_updated_by is table of amlm_ars_company_result_inf.updated_by %type;type t_key_value is table of amlm_ars_company_result_inf.key_value %type;type t_organno is table of amlm_ars_company_result_inf.organno %type;type t_is_offence is table of amlm_ars_company_result_inf.is_offence %type;type t_cust_pc_type is table of amlm_ars_company_result_inf.cust_pc_type %type;type t_cust_name is table of amlm_ars_company_result_inf.cust_name %type;type t_proce_status is table of amlm_ars_company_result_inf.proce_status %type;type t_data_date is table of amlm_ars_company_result_inf.data_date %type;type t_partit_flag is table of amlm_ars_company_result_inf.partit_flag %type;s_id_amlm_ars_company_resultt_id_amlm_ars_company_result ;s_batch_seq t_batch_seq ;s_cust_seq t_cust_seq ;s_group_seq t_group_seq ;s_series_code t_series_code ;s_company_client_id t_company_client_id ;s_company_risk_level t_company_risk_level ;s_client_worth t_client_worth ;s_point_template_score t_point_template_score ;s_point_template_id t_point_template_id ;s_formula_id t_formula_id ;s_attribute_id t_attribute_id ;s_next_risk_date t_next_risk_date ;s_client_type t_client_type ;s_status t_status ;s_group_risk_level t_group_risk_level ;s_created_date t_created_date ;s_created_by t_created_by ;s_updated_date t_updated_date ;s_updated_by t_updated_by ;s_key_value t_key_value ;s_organno t_organno ;s_is_offence t_is_offence ;s_cust_pc_type t_cust_pc_type ;s_cust_name t_cust_name ;s_proce_status t_proce_status ;s_data_date t_data_date ;s_partit_flag t_partit_flag ;/* cursor cur_result(c_date_1 date, c_date_1d varchar2) is select r.*, trunc(sysdate) data_date, c_date_1d - 1 partit_flag from amlm_ars_company_result r where exists (select group_seq from (select re.group_seq from aml_centric_task t, amlm_ars_company_result re where t.relevancy_id = re.id_amlm_ars_company_result and t.task_type in ('030102', '030202') --新开复核、存量复核 and t.task_status = '03' --已完成 and trunc(t.updated_date) between c_date_1 and trunc(sysdate) - 1 union all select re.group_seq from amlm_ars_company_result re, amlm_ars_adjust ad where re.id_amlm_ars_company_result = ad.id_amlm_ars_company_result and ad.adjust_result = '1' --调整通过 and trunc(ad.adjust_date) between c_date_1 and trunc(sysdate) - 1) s where s.group_seq = r.group_seq);*/ cursor cur_result(c_date_1 date, c_date_1d varchar2) is select r.*, trunc(sysdate) data_date, c_date_1d - 1 partit_flag from amlm_ars_company_result r where series_code = 'PA002' and proce_status = '4' and trunc(updated_date) between c_date_1 and trunc(sysdate) - 1; bulk_errors exception; pragma exception_init(bulk_errors, -24381);begin if trunc(p_sysdate) > trunc(sysdate) then p_msg := '传入时间不能大于系统时间'; return; end if; select count(1) into v_count from fxq_status where data_date = trunc(p_sysdate) and status_sign = 'Y'; if v_count > 0 then p_msg := '同一天正常跑完的数据不能重复执行'; return; end if;--取数日期 select nvl(nvl(p_sysdate, max(trunc(data_date))), trunc(sysdate) - 1) into v_sysdate from fxq_status where status_sign = 'Y'; --获取主键ID, nvl(获取数据日期,1天前的日期), 获取当前是星期几做为分区标识 select sys_guid(), v_sysdate, to_char(trunc(sysdate), 'd') into v_guid, v_date_1, v_date_1d from dual; --日志信息S proc_log(v_guid, v_proc, null, 'S', '从结果表获取复核通过的数据写入接口表开始', p_user); --清除之前失败的数据 for i in (select to_char(data_date - 1, 'd') d from fxq_status where status_sign = 'N') loop v_sql := 'alter table amlm_ars_company_result_inf truncate partition t_range_'||i.d||' update indexes'; execute immediate v_sql; end loop; --删除下个分区的数据 v_sql := 'alter table amlm_ars_company_result_inf truncate partition t_range_'||v_date_1d||' update indexes'; execute immediate v_sql; open cur_result(v_date_1, v_date_1d); loop fetch cur_result bulk collect into s_id_amlm_ars_company_result , s_batch_seq , s_cust_seq , s_group_seq , s_series_code , s_company_client_id , s_company_risk_level , s_client_worth , s_point_template_score , s_point_template_id , s_formula_id , s_attribute_id , s_next_risk_date , s_client_type , s_status , s_group_risk_level , s_created_date , s_created_by , s_updated_date , s_updated_by , s_key_value , s_organno , s_is_offence , s_cust_pc_type , s_cust_name , s_proce_status , s_data_date , s_partit_flag limit 5000; exit when s_id_amlm_ars_company_result.count = 0; begin forall i in 1..s_id_amlm_ars_company_result.count save exceptions --从结果表获取复核通过的数据写入接口表 insert into amlm_ars_company_result_inf(id_amlm_ars_company_result ,batch_seq ,cust_seq ,group_seq ,series_code ,company_client_id ,company_risk_level ,client_worth ,point_template_score ,point_template_id ,formula_id ,attribute_id ,next_risk_date ,client_type ,status ,group_risk_level ,created_date ,created_by ,updated_date ,updated_by ,key_value ,organno ,is_offence ,cust_pc_type ,cust_name ,proce_status ,data_date ,partit_flag )values( s_id_amlm_ars_company_result (i),s_batch_seq (i),s_cust_seq (i),s_group_seq (i),s_series_code (i),s_company_client_id (i),s_company_risk_level (i),s_client_worth (i),s_point_template_score (i),s_point_template_id (i),s_formula_id (i),s_attribute_id (i),s_next_risk_date (i),s_client_type (i),s_status (i),s_group_risk_level (i),s_created_date (i),s_created_by (i),s_updated_date (i),s_updated_by (i),s_key_value (i),s_organno (i),s_is_offence (i),s_cust_pc_type (i),s_cust_name (i),s_proce_status (i),s_data_date (i),s_partit_flag (i) ); commit; v_count := v_count + s_id_amlm_ars_company_result.count; exception when bulk_errors then for i in 1 .. sql%bulk_exceptions.count loop k := k + 1; proc_log(null, v_proc, dbms_utility.format_error_backtrace, sqlerrm(-1 * sql%bulk_exceptions(i).error_code), '从结果表获取复核通过的数据写入接口表 失败', null); end loop; end; end loop; if k = 0 then --更新全表(主要是把为N的数据更新为Y) update fxq_status set status_sign = 'Y' where status_sign = 'N'; --状态信息 proc_status('Y', v_count, sysdate, p_user); --日志信息E proc_log(v_guid, v_proc, null, 'E', '从结果表获取复核通过的数据写入接口表成功', p_user); p_msg := 'Y'; else v_count := v_count - k; --状态信息 proc_status('N', v_count, sysdate, p_user); p_msg := 'N'; end if;commit;exception when others then rollback; p_msg := 'N'; proc_log(v_guid, v_proc, dbms_utility.format_error_backtrace, sqlerrm, '从结果表获取复核通过的数据写入接口表失败', p_user); end proc_company_result_insert_inf;--*********************************************************************************--功能说明:-- 从结果表(amlm_ars_company_result)把复核通过的数据写入到接口表(amlm_ars_company_result_inf)-- 供JOB掉用 每天凌晨0点运行--参数说明:-- p_user 用户-- p_sysdate 日期-- p_msg Y:正常 返回其它值为异常--创建说明:创建者 创建日期-- xxx 2015-04-27--修改历史:修改者 修改日期 修改原因(简要说明)-- 暂无 暂无 暂无--*********************************************************************************procedure job_company_result_insert_infis v_msg varchar2(4000);begin proc_company_result_insert_inf(null, null, v_msg);end;end fxq_risk_pkg;/
0 0
- 一个完整的示例包体
- 一个完整的Oracle触发器示例
- 一个完整的php项目示例
- 一个动态游标的完整示例
- React Router的一个完整示例
- 一个java类的完整示例:
- 一个完整的jQuery datatable示例
- React Router的一个完整示例
- 一个Native Service的完整示例
- 一个Native Service的完整示例
- 一个完整的触发器文件示例
- 一个Lex/Yacc完整的示例(转)
- 一个完整包的开发实例
- PLSQL中关于包的一个示例
- 一个超简单的闭包示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- Android 性能优化(七)——MAT使用
- 允许ubuntu下mysql远程连接
- Ant自动编译打包&发布 android项目
- try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行,什么时候被执行,还是在return之后执行?
- Insert Interval
- 一个完整的示例包体
- 20150527
- MVN命令行创建工程及注意事项
- 关于感知学习模型机中空间任一点到超平面的距离公式的推导过程
- 移动端真机调试终极利器-BrowserSync
- ECC加密算法入门介绍
- 脚本调试: gzip ** unexpected end of file perl
- SNR信噪比
- MySQL和PHP页面同时正确显示中文 & PHP date函数的用法