在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选项是指”省略列标题的打印“。
本文介绍如何在shell脚本中使用db2-x命令从DB2数据库查询数据,包括获取指定日期的下一日期和获取表中记录数的方法。
8294

被折叠的 条评论
为什么被折叠?



