简体   繁体   English

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

[英]How to use password containing @ with sqlplus 18, 19 or 21 on linux?

I have ORACLE account with at sign (@) into password.我的 ORACLE 帐户带有 at 符号 (@) 到密码。

I was using sqlplus 12 and I can handle this special character with this syntax :我使用的是 sqlplus 12,我可以使用以下语法处理这个特殊字符:

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

Using now sqlplus 19, this doesn't work anymore.现在使用 sqlplus 19,这不再起作用了。 And after many tests (sqlplus v18 v19 and v21) on multiple OS (RHEL7 RHEL8 CentOS7), the problem is the same.并且在多个操作系统(RHEL7 RHEL8 CentOS7)上经过多次测试(sqlplus v18 v19和v21),问题是一样的。 I've tested a lot of escape methods and search all over internet without finding anything that works.我已经测试了很多逃生方法并在整个互联网上搜索,但没有找到任何有效的方法。

The problem seems specific to @ sign, I can escape a !这个问题似乎特定于 @ 符号,我可以逃避一个! with a \\ for example.以 \\ 为例。

EDIT : I need to automate this, so solution with human interaction are not solution to my problem.编辑:我需要自动化这个,所以人机交互的解决方案不能解决我的问题。

You can overcome this issue by connecting inside sqlplus , which by the way is much better if you want to encapsulate the connection inside a shell script.您可以通过在sqlplus内部进行连接来解决此问题,顺便说一下,如果您想将连接封装在 shell 脚本中,这会更好。

Let me show you ( Oracle 19c over Red Hat 7 )让我向您展示(Oracle 19c over 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.

If you connect in command line, it does not work如果在命令行中连接,它不起作用

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

But, if you connect inside, it does work但是,如果你在里面连接,它确实有效

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

Based on @Roberto Hernandez's answer, I've used his solution modified a bit to work inside script without the need to type password interactively :根据@Roberto Hernandez 的回答,我使用他的解决方案进行了一些修改以在脚本内部工作,而无需交互输入密码:

sqlplus /nolog << EOF\\nconn /""@:1521/\\n@"" sqlplus /nolog << EOF\\nconn /""@:1521/\\n@""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM