批处理脚本在Oracle中为不同的模式运行sql脚本

时间:2014-12-11 09:12:37

标签: oracle batch-file jenkins

我目前正在寻找执行以下操作的批处理脚本:

  1. 使用以下格式接受来自文本文件的变量:
  2. ..\xxx.sql<space>schema
    ..\xxx.pkb<space>schema
    ..\xxx.pks<space>schema
    ..\xxx.prc<space>schema
    
    1. 根据文本文件中提供的架构名称连接到实例。我只有1个DB节点。
    2. 按顺序执行文件并将其提交到数据库
    3. 这是我迄今为止所做的。但是,这不支持不同的模式/密码。

      @echo off
      
      SET SCHEMA_NAME=Test_123
      SET PASSWORD=1234
      
      echo ================================================
      echo Identifying files to be written into database...
      echo ================================================
      echo.
      rem -- Display list of files in the deployment directory
      for /r %%i in (*) do echo %%i
      echo.
      echo.
      echo ================================================
      echo Establishing connection to Elixir UAT DB...
      echo ================================================
      echo.
      rem -- Change working directory to which the sqlplus.exe resides
      Pushd C:\Oracle\product\11.2.0\client_1\BIN
      rem -- Makes SQLPlus exits upon completion of the executing the files
      rem -- This assist the user without modifying each sql file ending with 'exit' command
      echo exit | sqlplus %SCHEMA_NAME%/%PASSWORD%@TESTUATDB @C:\Users\Desktop\Driver.sql
      
      cmd /k
      
      
      Driver.sql:
      @C:\Users\sgarmkez\Desktop\ShowTimeStamp.sql
      @C:\Users\sgarmkez\Desktop\ShowTimeStamp2.sql
      

      完成后,我将使用Jenkins创建一个调用此批处理文件来执行部署到Oracle数据库的作业。如果还有其他方法,请告诉我。

1 个答案:

答案 0 :(得分:0)

以下代码可以帮助您使用Linux:

#! /bin/bash  

SCHEMA_NAME=schema
PASSWORD=password
IP=127.0.0.1
PORT=1521
SID=orcl

for SQLFile in `cat ./listof_sql_files.txt`
do
    sqlplus $SCHEMA_NAME/$PASSWORD@$IP:$PORT/$SID @$j
done

在Windows中,以下代码可以提供帮助:

FOR / F %% sqlfile IN(listof_sql_files.txt)DO sqlplus username/password@127.0.0.1:1521/ orcl @ %% sqlfile

注意: 您需要放置架构,密码,IP,端口和SID 还要根据系统中的文件位置来考虑文件。