一个小的etl调度,需要将存储过程执行情况进行返回并控制其后续依赖是否执行,本人只是将调用执行存储过程的shell脚本中存储过程输出参数返回,并没有写具体的控制程给大家,如果在这个思路上继续进行开发,那就是一个小的etl调度程序。
下面将各个脚本进行说明:(ex_produre.sh)
1.执行存储过程脚本
#!/bin/bash
user_name=$1
user_pass=$2
produre_name=$3
statis_sign=$4
sql_str=`
sqlplus -S $user_name/$user_pass as sysdba <<EOF
set linesize 800;
set long 2048576;
set serveroutput on;
var oi_return number;
call $user_name.$produre_name($statis_sign,:oi_return);
select :oi_return from dual;
exit
EOF`
echo "$sql_str"|sed -e '4,/^$/!d;/^$/d'|
while read run_return
do
echo $run_return
done
2.调执行存储过程的shell脚本(ex_proc.sh)
#!/bin/bash
sh ex_produre.sh etl jiangtao pdm_cust_act_behav_base 201003 |grep -v OI_RETURN |grep -v -| while read vi_result
do
#this date
echo $vi_result
if [ $vi_result -eq 0 ]
then
echo "this produre is normal run "
else
echo "this produre is not normal run "
fi
done
3.相关存储过程及建表脚本(这个大家可以做为模板使用,这可是一家大公司的模版,哈哈)
a.存储过程(pdm_cust_act_behav_base )
create or replace procedure pdm_cust_act_behav_base (is_month in varchar2, oi_return out number)
/** HEAD
* @name etl.pdm_cust_act_behav_base
* @caption ??????????
* @type ???
* @parameter is_month in varchar2 ???????YYYYMM
* @parameter oi_return out number ?????????0 ???-1 ??
* @description ??????????
* @target etl#tdm_cust_act_behav_base
* @source hwmk#tmm_ci_user_basic_m
* @middle
* @version 1.0
* @author
* @create-date
* @TODO ?
* @version
* @mender
* @modify_date
* @modify_desc
* @copyright
*/
-- ********************************************************************************
-- ????: etl.pdm_cust_act_behav_base
-- ????: ??????????
-- ????: is_month - ????
-- ????: oi_return - ?????????0 ???-1 ??
-- ????: hwmk.tmm_ci_user_basic_m
-- ????: etl.tdm_cust_act_behav_base
-- ????:
-- ????:
-- ????:
-- ????: v1.0
-- ????:
-- ????:
-- ????:
-- ????:
-- ????:
-- ********************************************************************************
is
vs_task_name varchar2(30); -- ????
vs_table_name varchar2(30); -- ???
vs_message varchar2(200); -- ????
vi_task_id integer; -- ??id
vi_month integer; -- ????
begin
vs_task_name := 'pdm_cust_act_behav_base';
vs_table_name := 'tdm_cust_act_behav_base';
-- ??????
etl.ps_log(vs_task_name, vs_table_name, is_month, 1, null, vi_task_id);
-- ??: ??????????
if (is_month is null) then
vs_message := '??????????';
etl.ps_log(null, null, null, 3, vs_message, vi_task_id);
oi_return := -1;
return;
end if;
------------------------------------------------------------
-- ??????
vi_month := to_number(is_month);
------------------------------------------------------------
insert into etl.tdm_cust_act_behav_base
(
statis_month,
serv_id
)
select
vi_month,
15204669284
from dual
;
commit;
------------------------------------------------------------
-- ??????
etl.ps_log(null, null, null, 2, null, vi_task_id);
-- ????
oi_return := 0;
return;
exception
when others then
-- ??????
vs_message := substr(sqlerrm, 1, 200);
-- ????
rollback;
-- ??????
etl.ps_log(null, null, null, 3, vs_message, vi_task_id);
-- ????
oi_return := -1;
return;
end;
/
b.存储过程(ps_log)
create or replace procedure ps_log
(
is_task_name in varchar2,
is_table_name in varchar2,
is_task_sign in varchar2,
ii_task_status in integer,
is_task_log in varchar2,
oi_task_id in out integer
)
-- ********************************************************************************
-- ????: etl.ps_log
-- ????: DW????????
-- ????: is_task_name - ????
-- is_table_name - ????
-- is_task_sign - ????, ???????????
-- ii_task_status - ????, 1 ?????, 2 ??????, 3 ??????
-- is_task_log - ????, ????[?????]?[??????],
-- ????[????]
-- oi_task_id - ??ID, ???2?3??????
-- ii_rowcount - ???
-- ????: oi_task_id - ??ID, ???1??????
-- ????:
-- ????: etl.ts_log
-- ????:
-- ????: ???
-- ????: 2010-02-01
-- ????: V1.0
-- ????:
-- ????:
-- ????:
-- ????:
-- ????: ????
-- ********************************************************************************
is
vs_err_msg varchar2(255); -- ??????
begin
if ii_task_status = 1 then
-- ????????????
select etl.seq_dw_log.nextval
into oi_task_id
from dual;
insert into etl.ts_log
(
task_id, -- ??ID
task_name, -- ????
table_name, -- ????
task_sign, -- ????
start_time, -- ??????
end_time, -- ?????????????
task_status, -- ????
task_log -- ????
)
values
(
oi_task_id,
is_task_name,
is_table_name,
is_task_sign,
sysdate,
null,
'1',
'?????'
);
elsif ii_task_status = 2 then
-- ????????????ID????????
update etl.ts_log
set end_time = sysdate,
task_status = '2',
task_log = '??????'
where task_id = oi_task_id;
else
-- ??????????ID?????????????
update etl.ts_log
set end_time = sysdate,
task_status = '3',
task_log = substr(is_task_log, 1, 200)
where task_id = oi_task_id;
end if;
commit;
-- ????
return;
exception
-- ????
when others then
-- ??????
vs_err_msg := substr(sqlerrm, 1, 200);
-- ????
rollback;
-- ??????
dbms_output.put_line('etl.ps_log: ' || vs_err_msg);
-- ????
return;
end;
/
c.建表脚本:
-- Create sequence
create sequence SEQ_DW_LOG
minvalue 1
maxvalue 999999999999999999999999999
start with 2731
increment by 1
cache 20;
create table TS_LOG
(
TASK_ID INTEGER,
TASK_NAME VARCHAR2(30),
TABLE_NAME VARCHAR2(30),
TASK_SIGN VARCHAR2(20),
START_TIME DATE,
END_TIME DATE,
TASK_STATUS VARCHAR2(1),
TASK_LOG VARCHAR2(200),
ROWCOUNT NUMBER
);
-- Create table
create table TDM_CUST_ACT_BEHAV_BASE
(
STATIS_MONTH NUMBER(10),
SERV_ID NUMBER(12)
);
相关推荐
linux系统中使用shell脚本对oracle存储过程进行编译
shell连接oracle数据库工具脚本:支持select/insert/update/delete 部署位置:/root/sysmonitor db:数据库文件夹 dbconfig.properties:数据库配置文件, dbConnectTest.sh:连接测试文件 dbExecurteSQL.sh:...
shell查看返回值,shell查看返回值,shell查看返回值,shell查看返回值,
在java代码中调用执行shell脚本,sqlldr导数与使用sqlplus在shell调用执行存储过程。 linux环境中有2个dba的用户:oracle、erm 还有1个web用户:erm 在linux环境中,这三个用户都可以直接在任意目录下执行该shell...
NULL 博文链接:https://woxiangbo.iteye.com/blog/2392852
1.在shell脚本执行python脚本时,需要通过python脚本的返回值来判断后面程序要执行的命令 例:有两个py程序 hello.py 代码如下: def main(): print “Hello” if __name__==’__main__’: main() world.py def ...
XP_CMDSHELL存储过程是执行本机的CMD命令,要求系统登陆有SA权限,也就是说如果获得SQLSERVER的SA命令,那就可以在目标机为所欲为了,知名软件“流光”使用的应该也是这个存储过程来实现在目标机上的操作。
NULL 博文链接:https://bicashy.iteye.com/blog/1522713
如果学习过高级语言比如java和c语言等,此时你要是获取一个函数的返回值,直接在函数里面写上return即可,然后在函数执行时将返回结果赋值给某个变量即可。但是在shell脚本中限制较多,因此如果我们想实现这样的功能...
最近研究了一下怎样使用shell 脚本连接数据库,然后执行查询语句。这样对于需要定时执行的脚本,我们可以建个 crontab 去定时执行。 先介绍一下客户端的安装: linux 环境需要用 sqlplus 客户端去连接oracle 数据库...
脚本中包括数据卸载,编码转换(GBK转UTF8),获取批次号(不同批次卸数使用),尾行加行数,FTP上传、以及增加注释了文件切割成多个文件的语句(针对大文件进行切割使用)。 注意:配置/etl/shell/config中的环境...
Oracle+DataX+存储过程实现异构库之间的数据同步。 0、设计文档 1、Oracle批量生成json文件 2、Oracle批量生成shell脚本 3、Oracle存过执行shell脚本
(里面包括简洁式安装教程)通过安装客户端,实现shell脚本直接连接oracle数据库和进行主机上面使用sqlldr数据导入。该资源已经安装好,解包到指定路径就可以使用,非root用户均可以使用。
Unix Oracle Shell Scripting
通过shell,定时备份数据库,并在数据库中记录备份日志 定时删除超过指定时间长度的备份文件
shell脚本可配置备份oracle数据库,完全可配置,使用方便。
shell 自动备份oracle 脚本,在redhat5 下自动备份oralce脚本
DECLARE @hr int --过程返回值 DECLARE @return varchar(255) --dll方法的返回值 DECLARE @src varchar(255),@desc varchar(255) ---过程的错误原因、描述 --1.创建对象 EXEC @hr = sp_OACreate 'PB_...