如何在linux上使用sqlplus 18、19或21使用包含@的密码?

问题描述 投票:0回答:3

我有 ORACLE 帐户,密码为 @ 符号。

我使用的是 sqlplus 12,我可以使用以下语法处理这个特殊字符:

sqlplus 'USER/\"@PWD\"@SERVER:1521/BASE'

现在使用sqlplus 19,这不再起作用了。并且经过在多个操作系统(RHEL7 RHEL8 CentOS7)上多次测试(sqlplus v18 v19 和 v21),问题都是一样的。我测试了很多逃生方法并在互联网上搜索但没有找到任何有效的方法。

问题似乎特定于@符号,我可以逃避!例如用 \ 。

编辑:我需要自动化此操作,因此与人机交互的解决方案并不能解决我的问题。

linux oracle sqlplus oracle19c
3个回答
4
投票

您可以通过内部连接来解决这个问题

sqlplus
,顺便说一句,如果您想将连接封装在 shell 脚本中,这会更好。

让我向您展示(Oracle 19c 与 Red Hat 7 相比)

SQL> select version from v$instance ;

VERSION
-----------------
19.0.0.0.0

SQL> create user test identified by "Ora@xde1" ;

User created.

SQL> grant connect to test ;

Grant succeeded.

如果您在命令行中连接,则不起作用

sqlplus test/"Ora@xde1"

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Sep 10 13:07:28 2021
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

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

但是,如果你在内部连接,它确实有效

sqlplus /nolog

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Sep 10 13:08:05 2021
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

SQL> conn test/"Ora@xde1"
Connected.
SQL> select 1 from dual ;

         1
----------
         1

0
投票

根据@Roberto Hernandez的回答,我使用了他的解决方案,对其进行了一些修改,以便在脚本内工作,而无需交互式输入密码:

sqlplus /nolog << EOF\nconn <user>/"<password>"@<server>:1521/<base>\n@"<script>"

0
投票

此方法需要用户交互,因此它不是本主题的答案,但它是使用 @ 符号提供密码的另一种方法。在我无法使用其他答案的情况下,我用它作为解决方法,所以我认为它也可能对某人有用。

无需密码执行sqlplus:

sqlplus <user>@<server>

SqlPlus 提示输入密码:

SQL*Plus: Release 21.0.0.0.0 - Production on Thu Feb 15 16:50:10 2024
Version 21.13.0.0.0

Copyright (c) 1982, 2022, Oracle.  All rights reserved.

Enter password:

此处用双引号将您的密码括起来,即,如果您的密码是

[password]
,则输入
"[password]"

我在 Windows 上使用 SQL*Plus 版本 21.13.0.0.0 进行了测试

© www.soinside.com 2019 - 2024. All rights reserved.