我执行了以下查询来查找我作为系统连接到的数据库的 SID:
SQL> select sys_context('userenv','instance_name') from dual;
SYS_CONTEXT('USERENV','INSTANCE_NAME')
--------------------------------------------------------------
orcl
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用以下命令连接到系统:
C:\>sqlplus system/system@orcl
SQL*Plus: Release 12.2.0.1.0 Production on Wed Aug 8 23:53:02 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
Run Code Online (Sandbox Code Playgroud)
在指定 SID 的同时,如何以系统身份连接到数据库?
你说使用SID?稍微展开连接字符串。就是这样:
\n\n我将使用 TNSPING 查找我需要的信息:
\n\nM:\\>tnsping orcl\n\nTNS Ping Utility for 64-bit Windows: Version 11.2.0.1.0 - Production on 09-KOL-2018 07:13:18\n\nCopyright (c) 1997, 2010, Oracle. All rights reserved.\n\nUsed parameter files:\nC:\\0_Oracle_library\\sqlnet.ora\n\n\nUsed TNSNAMES adapter to resolve the alias\nAttempting to contact (DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=db_kc11g) (PORT=1521)) (CONNECT_DATA= (SID=kc11g)))\nOK (20 msec)\nRun Code Online (Sandbox Code Playgroud)\n\n现在,连接:
\n\nM:\\>sqlplus scott/tiger@(description=(address=(protocol=tcp)(host=db_kc11g)(port=1521))(connect_data=(sid=kc11g)))\n\nSQL*Plus: Release 11.2.0.1.0 Production on \xe2\x95\x9aet Kol 9 07:14:05 2018\n\nCopyright (c) 1982, 2010, Oracle. All rights reserved.\n\n\nConnected to:\nOracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production\nWith the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,\nData Mining and Real Application Testing options\n\nSQL>\nRun Code Online (Sandbox Code Playgroud)\n\n或者,更短:
\n\nM:\\>sqlplus scott/tiger@db_kc11g:1521/kc11g\n\nSQL*Plus: Release 11.2.0.1.0 Production on \xe2\x95\x9aet Kol 9 07:16:59 2018\n\nCopyright (c) 1982, 2010, Oracle. All rights reserved.\n\n\nConnected to:\nOracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production\nWith the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,\nData Mining and Real Application Testing options\n\nSQL>\nRun Code Online (Sandbox Code Playgroud)\n