龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 操作系统 > LINUX系统 >

把SQL查询结果赋给shell变量

时间:2011-03-20 22:37来源:未知 作者:admin 点击:
分享到:
最近在看《基于Linux的Oracle数据库管理》这本书,根据书上的示例写的shell脚本, #!/bin/bash VALUE=`sqlplus -silent /nolog conn scott/tiger set pagesize 0 feedback off verify off heading off echo off numwidth 4 sel

  最近在看《基于Linux的Oracle数据库管理》这本书,根据书上的示例写的shell脚本,

  #!/bin/bash

  VALUE=`sqlplus -silent /nolog <

  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

  就能正确执行了。

精彩图集

赞助商链接