【问题标题】:Unable to run oracle query using bash script无法使用 bash 脚本运行 oracle 查询
【发布时间】:2020-09-07 09:22:50
【问题描述】:

我在 linux 中创建了一个包含内容的脚本-

sqlplus -silent test/test123@XYZ <<SQL_QUERY

select * from test.persons;

SQL_QUERY

这里-

测试 - 用户名

test@123 - 密码

XYZ - SID 名称

但是当我运行这个我得到错误 -

ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified


ERROR:
ORA-12162: TNS:net service name is incorrectly specified


SP2-0306: Invalid option.

谁能帮我解决这个问题? 提前致谢!

【问题讨论】:

  • 错误信息似乎很清楚:test/test123@XYZ 不是正确的连接标识符。
  • 不,@Barmar 不是这样。与TNS配置有关。
  • Shell 脚本,密码为 sqlplus 和特殊字符 stackoverflow.com/questions/48491926/…
  • 嘿@DmitryDemin,谢谢你的帮助。还有一个疑问,我如何将查询的输出存储到某个文件中?
  • "如何将查询的输出存储到某个文件中?"就像你从 shell 脚本中做任何其他事情一样。标准输出重定向。 'somecommand > myfile.txt' --- 这是一份礼物。你真的每个线程只会得到一个问题。

标签: linux bash oracle sh sqlplus


【解决方案1】:

基于此:

test - username
test@123 - password
XYZ - SID Name

我猜你实际上是在尝试运行:

sqlplus -silent test/test@123@XYZ

这就是 SQL*Plus 会因为 2 个“@”而抱怨的原因。

尝试将您的密码放在双引号中以避免这种情况。更好的方法是将密码放在连接钱包中,这样它就不会在脚本中编码。请参阅这篇文章了解如何执行此操作

https://connor-mcdonald.com/2015/09/21/connection-shortcuts-with-a-wallet/

【讨论】:

    猜你喜欢
    • 2013-06-24
    • 2011-08-10
    • 2018-08-15
    • 2015-03-24
    • 2023-01-18
    • 2014-02-20
    • 1970-01-01
    • 2012-09-14
    • 2013-01-12
    相关资源
    最近更新 更多