shell脚本sql赋值

 以下脚本功能是用shell脚本登录sqlplus连接oracle,将执行sql语句查询的结果赋值给shell脚本中的变量

 1 #!/bin/bash
 2 echo "开始连接数据库..."
 3 sqlplus -S "name/password" << !
 4 set pagesize 0
 5 set verify off
 6 set feedback off
 7 set echo off
 8 col coun new_value v_coun
 9 select count(*) coun from src.global_info where batchdate='20180309' and status='0';
10 exit v_coun
11 !
12 value="$?"
13 echo '查询总数为:'$value
14 if [ $value == 0 ];
15 then
16 echo "数据库状态错误,开始更新batchdate和status"
17 sqlplus -S "nbms_user2/nbms_user2" << !
18 update src.global_info set batchdate='20180305', status='0' where id =1;
19 select count(*) coun from src.global_info where batchdate='20180309' and status='0';
20 exit
21 !
22 echo "开始调用跑批脚本"
23 else
24                 echo "数据库状态正确!开始调用跑批脚本"
25                 #sh BMSRUNALL.sh
26 fi

 

posted @ 2018-03-09 17:22  喻雨晨  阅读(4150)  评论(0编辑  收藏  举报