発生した問題
SQL*Plusで@を含むパスワードを扱うとORA-12154エラーが発生する。
[oracle@XXXXXX ~]$ sqlplus USERNAME@SERVICENAME
SQL*Plus: Release 21.0.0.0.0 - Production on Tue Nov 29 14:42:00 2022
Version 21.6.0.0.0
Copyright (c) 1982, 2022, Oracle. All rights reserved.
Enter password:
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
環境
[oracle@XXXXXX ~]$ sqlplus -V
SQL*Plus: Release 21.0.0.0.0 - Production
Version 21.6.0.0.0
解決策
Enter password:
というパスワードプロンプト時に入力するパスワードの前後をダブルクォートで囲む。
[oracle@XXXXXX ~]$ sql /nolog
SQLcl: Release 21.2 Production on Tue Nov 29 16:51:37 2022
Copyright (c) 1982, 2022, Oracle. All rights reserved.
SQL> connect / as sysdba
Connected.
SQL> ALTER SESSION SET CONTAINER = pdb1;
Session altered.
SQL> CREATE USER PWDTEST IDENTIFIED BY "ABCDefgh1234@$";
User PWDTEST created.
SQL> GRANT CREATE SESSION TO PWDTEST;
Grant succeeded.
SQL> exit
Disconnected from Oracle Database 21c Standard Edition 2 Release 21.0.0.0.0 - Production
Version 21.6.0.0.0
[oracle@XXXXXX ~]$ sqlplus PWDTEST@SERVICENAME
SQL*Plus: Release 21.0.0.0.0 - Production on Tue Nov 29 16:55:18 2022
Version 21.6.0.0.0
Copyright (c) 1982, 2022, Oracle. All rights reserved.
Enter password: ←ここでABCDefgh1234@$と入力し、Enter
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
Enter user-name: [oracle@XXXXXX ~]$
[oracle@XXXXXX ~]$ sqlplus PWDTEST@SERVICENAME
SQL*Plus: Release 21.0.0.0.0 - Production on Tue Nov 29 16:55:33 2022
Version 21.6.0.0.0
Copyright (c) 1982, 2022, Oracle. All rights reserved.
Enter password: ←ここで"ABCDefgh1234@$"と入力し、Enter
Connected to:
Oracle Database 21c Standard Edition 2 Release 21.0.0.0.0 - Production
Version 21.6.0.0.0
SQL> exit
Disconnected from Oracle Database 21c Standard Edition 2 Release 21.0.0.0.0 - Production
Version 21.6.0.0.0
なお、その他ダブルクォートで囲む必要があるパスワードには、
- マルチバイト文字を含む
- 数字または特殊文字で始まり、英字を含む
- 英字、数字、および特殊文字以外の文字を含む
場合があるようだ。
https://support.oracle.com/knowledge/Middleware/2761789_1.html
@を含む場合については、
- SQLcl
- Oracle Data Pumpのexpdp, impdpコマンド
では、ダブルクォートで囲む必要はなく、SQL*Plus固有の問題であった。