在shell脚本中将表计数设置为变量..?

时间:2017-02-16 17:27:25

标签: mysql bash shell variables ingres

我希望在" count"中返回一个数值。我编写的SQL变量。不幸的是,我只是收到了Ingres错误消息。我有什么想法吗?

请参阅下面的shell脚本代码:

#!/bin/ksh
###############

count=$(sql db_name -s -N "SELECT COUNT(*) FROM temp_table;")

echo "Table count = $count"

请参阅以下Ingres错误:

Table count = INGRES TERMINAL MONITOR Copyright 2008 Ingres Corporation 
E_US0022 Either the flag format or one of the flags is incorrect,
    or the parameters are not in proper order.

预期结果:

Table count = 8

2 个答案:

答案 0 :(得分:1)

试试这个:

=>|Fri Feb 17|01:51:01|postgres@[STATION]:/var/lib/pgsql> ./test.sh
count ------- 3 (1 row)

=>|Fri Feb 17|01:51:04|postgres@[STATION]:/var/lib/pgsql> cat test.sh
#!/bin/bash

count=$(psql <<EOF
select count(*) from mdn_2 ;
EOF
)
# Prints the result captured from DB
echo $count

=>|Fri Feb 17|01:51:05|postgres@[STATION]:/var/lib/pgsql>

答案 1 :(得分:1)

-N不是Ingres终端监视器(sql命令)的有效标志。 你可能想要这样的东西(在bash中):

count=`echo "select count(*) from iitables;\g" | sql -S iidbdb`

有关接受的标志的更多信息,请参阅文档: http://docs.actian.com/#page/Ing_CommandRef%2FCommandRef_Body.1.235.htm%23