oracle批量更新数据库对象

待解决:

1.当连接数据库时出现错误,无法继续往下执行;

2.只捕捉了exec.log中ORA-错误,且需要手动处理;

          

 

核心代码

使用sqlplus连接远程数据库执行本地sql文件,批量更新数据库对象

sqlplus username/pwd@hostname: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/pwd@hostname:port/sid
username/pwd@hostname:port/sid2
username/pwd@hostname:port/sid3
username/pwd@hostname:port/sid4
username/pwd@hostname:port/sid5
username/pwd@hostname:port/sid6
username/pwd@hostname:port/sid7
username/pwd@hostname:port/sid8
username/pwd@hostname:port/sid9
...

 

你可能感兴趣的:(oracle)