During the connection to the Oracle Database server with the sqlplus
we may get an error with the ORA-12162 specifier. This error will prevent to connect to the Oracle Database Server.
在使用sqlplus
连接到Oracle数据库服务器的过程中,ORA-12162说明符可能会出错。 此错误将阻止连接到Oracle数据库服务器。
“ ORA-12162:TNS:net服务名称指定不正确”错误 (“ORA-12162: TNS:net service name is incorrectly specified” Error)
This error will be look like below. This error is caused by not setting $ORACLE_HOME and $ORACLE_SID environment variables for Linux and Windows Operating systems.
该错误如下所示。 此错误是由于未为Linux和Windows操作系统设置$ ORACLE_HOME和$ ORACLE_SID环境变量引起的。

检查$ ORACLE_HOME环境变量(Check $ORACLE_HOME Environment Variable)
$ORACLE_HOME
is important operating system variable used by Oracle Database. First we will check whether it is set or set properly with the echo
command like below in Linux.
$ORACLE_HOME
是Oracle数据库使用的重要操作系统变量。 首先,我们将使用echo
命令(如Linux中的以下命令)检查它是否已设置或正确设置。
$ echo $ORACLE_HOME

For windows we can list environment variables with env
command.
对于Windows,我们可以使用env
命令列出环境变量。
> env
在Windows和Linux中设置$ ORACLE_HOME环境变量 (Set $ORACLE_HOME Environment Variable in Windows and Linux)
We will set $ORACLE_HOME
environment variable. This will be used by related tools. We can set environment variable for Linux with export command like below.
我们将设置$ORACLE_HOME
环境变量。 相关工具将使用它。 我们可以使用如下导出命令为Linux设置环境变量。
$ export ORACLE_HOME="/home/oracle"
We can make this environment variable persistent between boots by adding this line to the .bashrc
file of the user.
通过将此行添加到用户的.bashrc
文件中,我们可以使此环境变量在两次引导之间保持不变。
We can use following tutorial to add ORACLE_HOME environment variable by using following tutorial in Windows operating system.
通过在Windows操作系统中使用以下教程,我们可以使用以下教程来添加ORACLE_HOME环境变量。
How To List, Set, Get Windows Environment Variables With Set Command In Command Line MS-DOS?
如何在命令行MS-DOS中使用Set命令列出,设置和获取Windows环境变量?
检查$ ORACLE_SID环境变量 (Check $ORACLE_SID Environment Variable)
We will check $ORACLE_SID
environment variable which also requires to solve error. We will use echo
command again.
我们将检查$ORACLE_SID
环境变量,该变量也需要解决错误。 我们将再次使用echo
命令。
$ echo $ORACLE_SID
在Linux中设置$ ORACLE_SID环境变量 (Set $ORACLE_SID Environment Variable in Linux)
Now the final step is setting $ORACLE_SID
in Linux environment. This will be used by sqlplus
to use as Oracle SID while connecting. In this case we will set XE
as SID.
现在,最后一步是在Linux环境中设置$ORACLE_SID
。 连接时, sqlplus
将使用它作为Oracle SID。 在这种情况下,我们将XE
设置为SID。
$ export ORACLE_SID="XE"
We can make this permanent by adding .bashrc
of the user like below.
我们可以通过添加用户的.bashrc
使其永久化,如下所示。
$ echo "export ORACLE_SID" >> ~/.bashrc