shell脚本获取select返回值

在shell脚本中,如果需要使用从DB2数据库中查询出来的数据,需要使用db2 -x命令:

1) 使用sql语句获取指定日期的下一日期

db2 connect to <databse-name>

db2 set schema <schema-name>

next_date=`db2 -x "select date('YYYY-MM-DD‘)+ 1 days from sysibm.sysdummy1"`

echo $next_date

2) 使用sql语句获取表中记录数

db2 connect to <databse-name>

db2 set schema <schema-name>

recordCount=`db2 -x "select count(*) from <table-name>" with ur`

echo $recordCount

 

经查询db2 ? options可知,-x选项是指”省略列标题的打印“。


版权声明:本文为wangxinzhen原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。