把ORACLE过程写入SHELL脚本
2015-09-15 13:43
525 查看
qingli> cat ql_mon.sh
nohup $ORACLE_HOME/bin/sqlplus -s <<!! >ql_mon_$1.log
declare
int_count number(10);
n number(10);
n_tmp number(10);
n_subsid number(18);
n_region number(5);
v_biztype varchar2(5);
e_My_Exception EXCEPTION;
e_nobiztype_Exception EXCEPTION;
v_table varchar2(100);
begin
int_count := 0;
n_tmp := 0;
v_biztype := null;
select lpad(v_biztype,2,'0') into v_biztype from dual;
for cc in (select t.*, t.rowid
from tmp_tbcsa.$1@TMP_HS_SJYZX.HEBEI.MOBILE.COM t
where flag =1 and t.modflag is null
/* and t.msisdn ='13503355958'*/
/*and t.servnumber = '13463068105'*/
) loop
begin
select count(*) into n_tmp from tbcs.iboss_spbizinfo where spid=cc.sp_code and bizcode = cc.oper_code;
if n_tmp > 0 then
select distinct t.biztype
into v_biztype
from tbcs.iboss_spbizinfo t
where t.spid=cc.sp_code
and t.bizcode = cc.oper_code;
else
RAISE e_nobiztype_Exception;
end if;
SELECT DISTINCT REGION
INTO n_REGION
FROM TBCS.REC_SERVNUMBER_REGION
WHERE BEGINNUM <= cc.msisdn
AND ENDNUM >= cc.msisdn;
if n_region in (310, 312, 314, 316, 318) then
select /*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) */
count(*)
into n_tmp
from tbcs.subscriber t
where t.servnumber = cc.msisdn
and t.active = 1
and t.region = n_region;
if n_tmp >0 then
select /*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) */
t.subsid
into n_subsid
from tbcs.subscriber t
where t.servnumber = cc.msisdn
and t.active = 1
and t.region = n_region;
else
n_subsid := null;
end if;
else
select /*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) */
count(*)
into n_tmp
from tbcs.subscriber@TBCSA_B.HEBEI.MOBILE.COM t
where t.servnumber = cc.msisdn
and t.active = 1
and t.region = n_region;
if n_tmp >0 then
select /*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) */
t.subsid
into n_subsid
from tbcs.subscriber@TBCSA_B.HEBEI.MOBILE.COM t
where t.servnumber = cc.msisdn
and t.active = 1
and t.region = n_region;
else
n_subsid := null;
end if;
end if;
/*select subsid
into n_subsid
from (select \*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) *\
t.subsid
from tbcs.subscriber t
where t.servnumber = cc.servnumber
and t.active = 1
and t.region = n_region
union
select \*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) *\
t.subsid
from tbcs.subscriber@TBCSA_B.HEBEI.MOBILE.COM t
where t.servnumber = cc.servnumber
and t.region = n_region
and t.active = 1);*/
if (n_subsid is null) then
RAISE e_My_Exception;
end if;
select count(*)
into n
from (select /*+ index(t,tbcs.IDX_SUBS_SPSERVICE_SUBSID)*/
*
from tbcs.subs_spservice t
where t.subsid = n_subsid
and t.region = cc.msisdn
and t.spid = cc.sp_code
and t.spbizid = cc.oper_code
and (t.enddate is null or t.enddate >= sysdate)
union
select /*+ index(t,tbcs.IDX_SUBS_SPSERVICE_SUBSID) */
*
from tbcs.subs_spservice@TBCSA_B.HEBEI.MOBILE.COM t
where t.subsid = n_subsid
and t.region = n_region
and t.spid = cc.sp_code
and t.spbizid = cc.oper_code
and (t.enddate is null or t.enddate >= sysdate));
if n > 0 then
RAISE e_My_Exception;
end if;
if v_biztype = '53' then
d110601.pro_djp_to_mca_cmmb(
n_region,
cc.msisdn,
v_biztype,
cc.sp_code,
cc.oper_code,
'07',
cc.chrg_type+1);
else
d110601.pro_djp_to_mca(n_region,
cc.msisdn,
v_biztype,
cc.sp_code,
cc.oper_code,
'07',
cc.chrg_type+1);
end if;
update tmp_tbcsa.$1@TMP_HS_SJYZX.HEBEI.MOBILE.COM t
set t.modflag = '1'
where t.rowid = cc.rowid;
int_count := int_count + 1;
if int_count = 1000 then
int_count := 0;
commit;
end if;
exception
when e_My_Exception then
update tmp_tbcsa.$1@TMP_HS_SJYZX.HEBEI.MOBILE.COM t
set t.modflag = '2'
where t.rowid = cc.rowid;
WHEN e_nobiztype_Exception THEN
update tmp_tbcsa.$1@TMP_HS_SJYZX.HEBEI.MOBILE.COM t
set t.modflag = '3'
where t.rowid = cc.rowid;
end;
end loop;
commit;
end;
/
exit;
这样运行:
nohup ql_mon.sh TMP_12580_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_HBGJ_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_SJZQ_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_WXTYJLB_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_QTY_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_SJSJ_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_SJYL_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_KX_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_SJB_BOSSMINUS_20110915 &
nohup $ORACLE_HOME/bin/sqlplus -s <<!! >ql_mon_$1.log
declare
int_count number(10);
n number(10);
n_tmp number(10);
n_subsid number(18);
n_region number(5);
v_biztype varchar2(5);
e_My_Exception EXCEPTION;
e_nobiztype_Exception EXCEPTION;
v_table varchar2(100);
begin
int_count := 0;
n_tmp := 0;
v_biztype := null;
select lpad(v_biztype,2,'0') into v_biztype from dual;
for cc in (select t.*, t.rowid
from tmp_tbcsa.$1@TMP_HS_SJYZX.HEBEI.MOBILE.COM t
where flag =1 and t.modflag is null
/* and t.msisdn ='13503355958'*/
/*and t.servnumber = '13463068105'*/
) loop
begin
select count(*) into n_tmp from tbcs.iboss_spbizinfo where spid=cc.sp_code and bizcode = cc.oper_code;
if n_tmp > 0 then
select distinct t.biztype
into v_biztype
from tbcs.iboss_spbizinfo t
where t.spid=cc.sp_code
and t.bizcode = cc.oper_code;
else
RAISE e_nobiztype_Exception;
end if;
SELECT DISTINCT REGION
INTO n_REGION
FROM TBCS.REC_SERVNUMBER_REGION
WHERE BEGINNUM <= cc.msisdn
AND ENDNUM >= cc.msisdn;
if n_region in (310, 312, 314, 316, 318) then
select /*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) */
count(*)
into n_tmp
from tbcs.subscriber t
where t.servnumber = cc.msisdn
and t.active = 1
and t.region = n_region;
if n_tmp >0 then
select /*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) */
t.subsid
into n_subsid
from tbcs.subscriber t
where t.servnumber = cc.msisdn
and t.active = 1
and t.region = n_region;
else
n_subsid := null;
end if;
else
select /*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) */
count(*)
into n_tmp
from tbcs.subscriber@TBCSA_B.HEBEI.MOBILE.COM t
where t.servnumber = cc.msisdn
and t.active = 1
and t.region = n_region;
if n_tmp >0 then
select /*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) */
t.subsid
into n_subsid
from tbcs.subscriber@TBCSA_B.HEBEI.MOBILE.COM t
where t.servnumber = cc.msisdn
and t.active = 1
and t.region = n_region;
else
n_subsid := null;
end if;
end if;
/*select subsid
into n_subsid
from (select \*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) *\
t.subsid
from tbcs.subscriber t
where t.servnumber = cc.servnumber
and t.active = 1
and t.region = n_region
union
select \*+ index(t,tbcs.IDX_SUBSCRIBER_SERVNUMBER) *\
t.subsid
from tbcs.subscriber@TBCSA_B.HEBEI.MOBILE.COM t
where t.servnumber = cc.servnumber
and t.region = n_region
and t.active = 1);*/
if (n_subsid is null) then
RAISE e_My_Exception;
end if;
select count(*)
into n
from (select /*+ index(t,tbcs.IDX_SUBS_SPSERVICE_SUBSID)*/
*
from tbcs.subs_spservice t
where t.subsid = n_subsid
and t.region = cc.msisdn
and t.spid = cc.sp_code
and t.spbizid = cc.oper_code
and (t.enddate is null or t.enddate >= sysdate)
union
select /*+ index(t,tbcs.IDX_SUBS_SPSERVICE_SUBSID) */
*
from tbcs.subs_spservice@TBCSA_B.HEBEI.MOBILE.COM t
where t.subsid = n_subsid
and t.region = n_region
and t.spid = cc.sp_code
and t.spbizid = cc.oper_code
and (t.enddate is null or t.enddate >= sysdate));
if n > 0 then
RAISE e_My_Exception;
end if;
if v_biztype = '53' then
d110601.pro_djp_to_mca_cmmb(
n_region,
cc.msisdn,
v_biztype,
cc.sp_code,
cc.oper_code,
'07',
cc.chrg_type+1);
else
d110601.pro_djp_to_mca(n_region,
cc.msisdn,
v_biztype,
cc.sp_code,
cc.oper_code,
'07',
cc.chrg_type+1);
end if;
update tmp_tbcsa.$1@TMP_HS_SJYZX.HEBEI.MOBILE.COM t
set t.modflag = '1'
where t.rowid = cc.rowid;
int_count := int_count + 1;
if int_count = 1000 then
int_count := 0;
commit;
end if;
exception
when e_My_Exception then
update tmp_tbcsa.$1@TMP_HS_SJYZX.HEBEI.MOBILE.COM t
set t.modflag = '2'
where t.rowid = cc.rowid;
WHEN e_nobiztype_Exception THEN
update tmp_tbcsa.$1@TMP_HS_SJYZX.HEBEI.MOBILE.COM t
set t.modflag = '3'
where t.rowid = cc.rowid;
end;
end loop;
commit;
end;
/
exit;
这样运行:
nohup ql_mon.sh TMP_12580_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_HBGJ_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_SJZQ_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_WXTYJLB_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_QTY_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_SJSJ_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_SJYL_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_KX_BOSSMINUS_20110915 &
nohup ql_mon.sh TMP_SJB_BOSSMINUS_20110915 &
相关文章推荐
- ORACLE declare 简单实例
- Oracle BIEE EVALUATE系列使用数据库函数
- oracle删除同一张表的重复记录
- 个人面试题(oracle数据库开发)(一)
- Oracle Sql相关记录
- Oracle中三种循环(For、While、Loop)
- oracle存储过程常用技巧
- Oracle数据库解锁
- oracle触发器(转载)
- Oracle11g R2 ORA-00845的错误:MEMORY_TARGET not supported on this system
- oracle 与OS的存储结构
- instantclient配置oracle客户端
- Oracle 11gR2 crs_stat 命令不再显示instance信息
- ORACLE-TRIGGER-ERROR 04098 触发器无效且未通过重新验证
- 開機自動啟動ORACLE
- Oracle使用——PLSQL的中文乱码显示全是问号
- Oracle to_char,to_date
- 不安装oracle直接使用PLSQL(转载)
- 未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。
- oracle 用Navicat创建的表的查询问题