当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
把SQL查询结果赋给shell变量
发布时间:2010/6/29 15:53:15 来源:城市学习网 编辑:ziteng
  最近在看《基于Linux的Oracle数据库管理》这本书,根据书上的示例写的shell脚本,
  #!/bin/bash
  VALUE=`sqlplus -silent /nolog <<END
  conn scott/tiger
  set pagesize 0 feedback off verify off heading off echo off numwidth 4
  select count( * ) coun from all_objects;
  exit;
  END`
  if [ "$VALUE" -gt 0 ]
  then
  echo "The number of rows is $VALUE."
  exit 0
  else
  echo "There is no row in the table."
  fi
  在执行时总报错误:
  ./sqlshell.sh: line 9: [: ####: integer expression expected
  书上写的应该没错,查找原因,看了一上我机器上的查询结果是:40620
  应该是显示的位宽不够,所以"$VALUE"值变成了一个错误的值。
  把numwidth 4 改成为 numwidth 5
  就能正确执行了。
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved