【发布时间】:2018-03-15 02:26:15
【问题描述】:
我编写了一个示例 shell 脚本,试图使用 SQLPLUS 执行一个 SQL 文件。
这是我的 shell 脚本
#!/bin/bash
username=$1
password=$2
TNS_entry=$3
schema_version=$(sqlplus -S '$username/$password@$TNS_entry' @schema.sql)
echo "Schema_number: $schema_version";
#./schema.sh username password '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST=SANDBOX.domain)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)
(SERVICE_NAME=orcl))'
执行此操作后,我遇到了 SQLPLUS 错误。
Schema_number: ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
但是,如果我手动运行它,我可以毫无问题地连接到 Oracle DB,这表明我的 SQLPLUS 连接字符串没有问题。我猜 shell 是这里的罪魁祸首,但无法弄清楚它在哪里引起了问题。
sqlplus username/password@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SANDBOX.domain)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))' @schema.sql
SQL*Plus: Release 12.2.0.1.0 Production on Wed Mar 14 21:07:37 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
有人可以看看这个并帮助我找出问题所在。
感谢和问候
圣人
【问题讨论】:
-
为什么不执行同样的
schema_version=sqlplus $username/$password('@$TNS_entry') @schema.sql -
我试过了,但 sqlplus 仍然抱怨 tns 条目