使用batch(批处理)执行文件夹下所有的sql script(脚本)并输出sqlplus内容至log文件

这是一个批处理脚本,用于在指定路径(C:/temp)下执行所有SQL文件,并将SQLPLUS的输出内容记录到以当前时间戳命名的日志文件中。脚本首先设置数据库连接信息,然后生成临时SQL文件,将所有SQL脚本内容合并并添加日志指令。最后,通过SQLPLUS执行临时文件中的SQL语句,完成后删除临时文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    1. @echo off
    2. rem "set the infos below, then it can be performed."
    3. rem "===================================="
    4. rem "PLEASE set the path of sql files"
    5. @set script_path=C:/temp
    6. rem "PLEASE set the connection of db server"
    7. @set db_conn=dbusername/dbpassword@dbsid
    8. rem "===================================="
    9. rem "get the time string "
    10. @set timeS=%DATE:/=%%TIME::=%
    11. rem "get the time string "
    12. @set tmpf=tmp%timeS:~0,14%.sql
    13. @set logf=log%timeS:~0,14%.txt
    14. rem "specify the log file "
    15. @echo spool %logf% >> %tmpf%
    16. rem "only the error msg"
    17. rem @echo set feedback off >>%tmpf%
    18. rem "copy the sql file to tmpfile "
    19. @for /R %script_path% %%a in (*.sql) do (
    20.     type %%a >> %tmpf%
    21.     echo.>> %tmpf%
    22. )
    23. rem "write print log command to tmpfile "
    24. @echo spool off >> %tmpf%
    25. rem "write exit; to tmpfile "
    26. @echo exit; >> %tmpf%
    27. rem "perform the sqls "
    28. @sqlplus %db_conn% @%tmpf%
    29. rem "del the tmpfile "
    30. @del %tmpf%
    31. @echo on
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值