SP2-0306:无效选项。通过shell脚本连接到DB时

时间:2017-10-13 06:14:07

标签: linux shell unix sqlplus

我有一个shell脚本,通过sqlplus连接到它来查询数据库,但我收到了无效选项错误.Below是我的脚本。

set -x
TodayDate=`date +%d-%m-%Y`

read_sql_stmt()
{
        typeset stmt=$1
        typeset login=$2
        echo "
                set feedback off verify off heading off pagesize 0
                $stmt;
                exit
                " | sqlplus -s login
}
#USER_PASS="bnpqa/bnpqa@MTS12C"
echo $USER_PASS
dnsmDate=`read_sql_stmt "select distinct(to_char(trunc(nse_update_date),'DD-MM-YYYY')) FROM DRV_NSE_SECURITY_MASTER" "$USER_PASS"`

echo "$dnsmDate"
if [ $TodayDate -gt $dnsmDate ]
then
echo "Success"
fi;

以下是使用set -x

进行调试时的输出
+++ date +%d-%m-%Y
++ TodayDate=13-10-2017
++ echo bnpqa/bnpqa@MTS12C
bnpqa/bnpqa@MTS12C
+++ read_sql_stmt 'select distinct(to_char(trunc(nse_update_date),'\''DD-MM-YYYY'\'')) FROM DRV_NSE_SECURITY_MASTER' bnpqa/bnpqa@MTS12C
+++ typeset 'stmt=select distinct(to_char(trunc(nse_update_date),'\''DD-MM-YYYY'\'')) FROM DRV_NSE_SECURITY_MASTER'
+++ typeset login=bnpqa/bnpqa@MTS12C
+++ echo '
                set feedback off verify off heading off pagesize 0
                select distinct(to_char(trunc(nse_update_date),'\''DD-MM-YYYY'\'')) FROM DRV_NSE_SECURITY_MASTER;
                exit
                '
+++ sqlplus -s login
++ dnsmDate='
SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]'
++ echo '
SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]'

SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]
++ '[' 13-10-2017 -gt SP2-0306: Invalid option. Usage: 'CONN[ECT]' '[{logon|/|proxy}' '[AS' '{SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM}]' '[edition=value]]' where '<logon>' ::= '<username>[/<password>][@<connect_identifier>]' '<proxy>' ::= '<proxyuser>[<username>][/<password>][@<connect_identifier>]' ']'
./FileUploadStatus.sh: line 21: [: 13-10-2017: integer expression expected

虽然我可以通过sqlplus用户名/密码@ DBNAME直接从我的终端连接到DB。

0 个答案:

没有答案