加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle – 从sql脚本返回值到shell脚本

发布时间:2020-12-12 13:50:34 所属栏目:百科 来源:网络整理
导读:我有shell脚本调用以下sql脚本: INSERT INTO SEMANTIC.COUNT_STATISTICS (...); UPDATE SEMANTIC.COUNT_STATISTICS SET PRNCT_CHANGE = 1.1; --want to store result of this bellow select statement in model_count variable select PRNCT_CHANGE FROM SE
我有shell脚本调用以下sql脚本:
INSERT INTO SEMANTIC.COUNT_STATISTICS (...);
     UPDATE SEMANTIC.COUNT_STATISTICS 
     SET PRNCT_CHANGE = 1.1;


  --want to store result of this bellow select statement in model_count variable

      select PRNCT_CHANGE
      FROM SEMANTIC.COUNT_STATISTICS
      WHERE model = '&MY_MODEL'
      AND NEW_DATE = (
                      select max(NEW_DATE)
                      from SEMANTIC.COUNT_STATISTICS
                      where MODEL = '&MY_MODEL'
                     );

现在,如何将此PERCENTAGE_NUMBER变量返回到我的shell脚本?

我的shell脚本如下:

#!/bin/bash
#
# setup oracle,java,and d2rq environment
. /etc/profile.d/oracle.sh
. /etc/profile.d/java.sh
. /etc/profile.d/d2rq.sh

cd /opt/D2RQ

model_count=$(sqlplus user/pass @count.sql 'MODEL')

if ["$model_count" > 0]; then
   echo "percentage count is positive"
else
   echo "its negative"

我想将最后一个SELECT语句结果存储到shell脚本中的model_count变量中.

谁知道为什么不工作?

使用bash函数的bash示例(注意!数据库操作系统身份验证“/”)
#!/bin/bash

get_count () {
    sqlplus -s / <<!
    set heading off
    set feedback off
    set pages 0
    select count(*) from all_objects where object_type = '$1'; 
!
}

count=$(get_count $1)

echo $count

if [ "$count" -gt 0 ]; then
    echo "is greater than zero"
else
    echo "is less or equal to zero"
fi


~/tmp/ $./count.sh INDEX
2922
is greater than zero
~/tmp/ $./count.sh TABLE
1911
is greater than zero
~/tmp/ $./count.sh FUNCTION
226
is greater than zero
~/tmp/ $./count.sh "SUPEROBJECT"
0
is less or equal to zero

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读