版权声明:本文为博主DbaH原创文章,允许转载,需要标明出处 https://blog.csdn.net/u011592350/article/details/78670486
批处理文件调用oracle实例
方法一:通过SQL文件调用匿名程序块
oracle函数准备
drop table testBat;
create table testBat(
batchid varchar2(16),
first_date date,
machine varchar(30)
);
create or replace function FTESTBAT(p_batchid varchar2,p_first_date varchar2,p_machine varchar2)
return number as
v_date date;
begin
v_date:=to_date(p_first_date,'yyyy-mm-dd hh24:mi:ss');
insert into testBat(Batchid, First_Date,Machine) values(p_batchid,v_date,p_machine);
commit;
return 0;
end;
SQL文件准备insert.sql
declare
v_result number;
begin
v_result := FTESTBAT('&1','&2','&3');
dbms_output.put_line(v_result);
end;
/
调用批处理文件insert.bat
@echo off
rem 获取当前时间作为批次号
if "%time:~0,1%"==" " (set curr_time=%date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time:~3,2%%time:~6,2%) else (set curr_time=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%ti me:~6,2%)
echo %curr_time%
echo %1
rem 获取主机名
echo computername=%computername%
rem 指定时间
set restart_time=08:00:00
set restart=%date:~0,4%-%date:~5,2%-%date:~8,2% %restart_time%
echo %restart%
rem 调用函数的第三个参数需要根据不同主机进行调整
sqlplus linml/123456@JBITDB @insert.sql '%curr_time%' "%restart%" "%computername%"
方法二:通过SQL文件直接执行语句
SQL文件准备
set heading off
set pagesize 0;
set feedback off;
set verify off;
set echo off;
select 'str:'||DBAH.FGET_CALL_IDS from dual;
exit
批处理文件
@echo off
set result=c:\test\result_2017.txt
set tmp_file=c:\test\tmp_file.txt
set out=c:\test\out.log
set phonefile=c:\test\phonefile.txt
sqlplus test/***@TEST @check_call_function.sql > %result%
If errorlevel 1 (
Echo get error!
) Else (
Echo get success!
)
批处理相关知识总结
获取当前日期和时间
格式:%date:~x,y%以及%time:~x,y%
说明:x是开始位置,y是取得字符数
echo %date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
注意:上述写法造成的问题是当小于10点时,日期与时间之间会出现一个空格为避免出现这种情况,可以在外层增加一个判断语句
IF判断语句
bat批处理 if 命令示例详解_DOS/BAT_脚本之家 http://www.jb51.net/article/14986.htm
注释方式
- :: 注释内容(第一个冒号后也可以跟任何一个非字母数字的字符)
- rem 注释内容(不能出现重定向符号和管道符号)
- echo 注释内容(不能出现重定向符号和管道符号)〉nul
- if not exist nul 注释内容(不能出现重定向符号和管道符号)
- :注释内容(注释文本不能与已有标签重名)
- %注释内容%(可以用作行间注释,不能出现重定向符号和管道符号)
- goto 标签 注释内容(可以用作说明goto的条件和执行内容)
- :标签 注释内容(可以用作标签下方段的执行内容)