一、建一个批处理文件,如Export.bat,内容如下:
@echo off
rem 此脚本由Shinetan编写
if "%1"=="" goto end
rem dds/ddsowner1@dds
set Source=dds/dds.owner@dds
set Target=dds/ddsowner@dev.ico
set ParaTables=%1
set OperateTime=
:SetTime
if "%time:~0,1%"==" " goto TimeSmallThen10
:TimeLargerThen10
set OperateTime=%date:~0,4%-%date:~5,2%-%date:~8,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%
goto SetTimeEnd
:TimeSmallThen10
set OperateTime=%date:~0,10%_%time:~1,1%-%time:~3,2%-%time:~6,2%
goto SetTimeEnd
:SetTimeEnd
rem 创建以时间为名称的目录
md %OperateTime%
type nul >%OperateTime%\SQL.inp
rem echo drop table %ParaTables%; >%OperateTime%\SQL.inp
:LOOP
IF [%1]==[] GOTO LOOP_END
REM 保存参数,以做回归分析
echo drop table %1; > %OperateTime%\tmp.inp
type %OperateTime%\SQL.inp >> %OperateTime%\tmp.inp
type %OperateTime%\tmp.inp > %OperateTime%\sql.inp
set ParaTables=%ParaTables%,%1
SHIFT
GOTO LOOP
:LOOP_END
echo 导出源表
exp %Source% Tables=%ParaTables% File=%OperateTime%\Source.dmp direct=y log=%OperateTime%\Exp.log
echo 备份目标表
exp %Target% Tables=%ParaTables% File=%OperateTime%\Backup.dmp direct=y log=%OperateTime%\Backup.log
echo 删除目标表
sqlplus %Target% <%OperateTime%\SQL.inp
echo 导入新表
imp %Target% Tables=%ParaTables% File=%OperateTime%\Source.dmp log=%OperateTime%\Imp.log
rem 记录
echo Source=%Source% >>%OperateTime%\Export.log
echo Target=%Target% >>%OperateTime%\Export.log
echo Tables=%ParaTables% >>%OperateTime%\Export.log
echo Ok.
:END
pause
@echo on
二、调用方法:Export [table1,table2,table3,...]