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.

“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.

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.

$ echo $ORACLE_HOME

For windows we can list environment variables with env command.

> env

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.

$ 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.

We can use following tutorial to add ORACLE_HOME environment variable by using following tutorial in Windows operating system.

How To List, Set, Get Windows Environment Variables With Set Command In Command Line MS-DOS?

Check $ORACLE_SID Environment Variable

We will check $ORACLE_SID environment variable which also requires to solve error. We will use echo command again.

$ echo $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.

$ export ORACLE_SID="XE"

We can make this permanent by adding .bashrc of the user like below.

$ echo "export ORACLE_SID" >> ~/.bashrc