windows下通过bat脚本调用sql脚本

main.bat

rem '------------make sure the num of  param is correct--------'
set /a num=0
set /a num_of_params=4
for %%a in (%*) do set /a num+=1
if %num% neq %num_of_params% (
	echo 'please input %num_of_params% three args as follows: username, userpasswd, dmp_dir_path'
	goto :eof
)

rem '---------get input params--------'
set user_name=%1%
set user_password=%2%
set data_dmp_dir=%3%
set size_of_perfile=%4%

rem '----------create logical directory-------'
sqlplus / as sysdba @create_dir.sql %user_name% %data_dmp_dir%

rem '--------expdp data of schema--------'
expdp %user_name%/%user_password%  schemas=%user_name%  dumpfile=%user_name%_%%U.dmp directory=dmp_dir logfile=%user_name%.log  filesize=%size_of_perfile%


create_dir.sql

show user;
grant dba to &1;
define dump_dir_path=&2
create or replace directory dmp_dir as '&dump_dir_path';
grant read , write on directory dmp_dir to &1;
quit;

#涉及知识点

  • bat脚本
    • 注释: rem
    • 定义变量: set /a key=value
    • 获取参数:set user_name=%1% 获取第一个参数
    • sqlplus调用sql文件 : sqlplus link_str @sql_script.sql
  • sql脚本
    • 获取参数:第一个参数 &1
    • 自定义变量:define dump_dir_path='E:/hello'
posted @ 2019-02-03 22:44  岳麓丹枫  阅读(894)  评论(0编辑  收藏  举报