批处理文件调用oracle实例

来源:互联网 发布:豆瓣读书软件 编辑:程序博客网 时间:2024/05/17 21:53

批处理文件调用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 asv_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
declarev_result number;beginv_result := FTESTBAT('&1','&2','&3');dbms_output.put_line(v_result);end;/
调用批处理文件insert.bat
@echo offrem 获取当前时间作为批次号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 %1rem 获取主机名echo computername=%computername%rem 指定时间set restart_time=08:00:00set 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 offset pagesize 0;set feedback off;set verify off;set echo off;select 'str:'||DBAH.FGET_CALL_IDS from dual;exit
批处理文件
@echo offset result=c:\test\result_2017.txtset tmp_file=c:\test\tmp_file.txtset out=c:\test\out.logset phonefile=c:\test\phonefile.txtsqlplus 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的条件和执行内容)
  • :标签 注释内容(可以用作标签下方段的执行内容)
原创粉丝点击