zoukankan      html  css  js  c++  java
  • shell调用sqlplus批量执行sql文件

    在最近的工作中,经常需要批量执行一些DML, DDL, PL/SQL语句或导入一些Function, Procedure。因为support的国家比较多,常常需要一个登陆到一个国家的数据库上执行完成后再登陆到另一个国家执行,很是麻烦。今天得空就写了个shell来批量处理。

    #Env.sh中定义一常用的变量,ORACLE_SID,$AU_USER,$AU_PWD等。
    . /home/oracle/shell/Env.sh

    AU="$AU_USER/$AU_PWD"
    CN="$CN_USER/$CN_PWD"
    US="$US_USER/$US_PWD"
    UK="$UK_USER/$UK_PWD"

    #把所有国家的数据库连接信息放入到一个数组中
    set -A ctl_list $AU $CN $US $UK

    #对数组进行循环遍历,取出数据库连接信息;
    #用spool...append收集执行情况信息;
    #"@/home/oracle/shell/load.sql;"执行load.sql文件

    for i in ${ctl_list[@]}
    do
       sqlplus -L $i@$ORACLE_SID <<EOF
       set serveroutput on;   
         spool /home/oracle/shell/load.log append   
         @/home/oracle/shell/load.sql;
         spool off
       QUIT
    EOF
    done

     

    #用“@”执行sql文件时,如果每条sql后面要跟上“;”,如果有pl/sql代码,需要在最后加上“/”。
    [oracle@toughhou shell]$ cat load.sql

    create table student(
    st_no   number primary key,
    st_name varchar2(10)
    );

    insert into student(st_no,st_name) values(1001,"Tough1");
    insert into student(st_no,st_name) values(1002,"Tough2");
    insert into student(st_no,st_name) values(1003,"Tough3");
    insert into student(st_no,st_name) values(1004,"Tough4");

    alter table student add (age number);

    create or replace procedure my_proc
    as 
    begin
        dbms_output.put_line("Date: " || sysdate);
    end my_proc;
    /

     

  • 相关阅读:
    普通文本输入数学符号的方式
    Chrome crx离线插件下载及安装
    Solidworks常见问题一览
    数学学术资源站点(zz)
    最难读的20个英文单词
    运用html5 canvas做飞机大战游戏(2)
    html
    运用html5 canvas做飞机大战游戏(1)
    js
    css
  • 原文地址:https://www.cnblogs.com/toughhou/p/3778784.html
Copyright © 2011-2022 走看看