oracle批量更新数据库对象
程序员文章站
2022-06-02 15:46:20
...
待解决:
1.当连接数据库时出现错误,无法继续往下执行;
2.只捕捉了exec.log中ORA-错误,且需要手动处理;
核心代码
使用sqlplus连接远程数据库执行本地sql文件,批量更新数据库对象
sqlplus username/[email protected]:port/sid @test.sql
bat文件
@echo off
chcp 936
Title 批量执行sql
set file_path=%~dp0
echo running...
echo start update > exec.log
for /f "usebackq " %%i in ("%file_path%db.conf") do (
rem echo %%i >> exec.log
echo %%i
sqlplus %%i @test.sql >>exec.log
)
FINDSTR "ORA-" exec.log
echo end
pause >nul
test.sql文件
可以写ddl和dml语句
create or replace function getMax(num1 in number, num2 in number) return number is
FunctionResult number;
begin
IF num1 >num2
THEN FunctionResult := num1;
ELSE FunctionResult := num2;
END IF;
return(FunctionResult);
end getMax;
--以下为结束标识
/
exit;
db.conf文件配置数据库连接信息
username/[email protected]:port/sid
username/[email protected]:port/sid2
username/[email protected]:port/sid3
username/[email protected]:port/sid4
username/[email protected]:port/sid5
username/[email protected]:port/sid6
username/[email protected]:port/sid7
username/[email protected]:port/sid8
username/[email protected]:port/sid9
...
上一篇: 多个线程对象,复制同一个文件
推荐阅读