Oracle “ORA-12162: TNS:net service name is incorrectly specified” Error and Solution – POFTUT

Oracle “ORA-12162: TNS:net service name is incorrectly specified” Error and Solution

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.

"ORA-12162: TNS:net service name is incorrectly specified" Error

“ORA-12162: TNS:net service name is incorrectly specified” Error

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.

Check $ORACLE_HOME Environment Variable

Check $ORACLE_HOME Environment Variable

For windows we can list environment variables with env command.

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.

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.

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.

LEARN MORE  Oracle Database "sqlplus: error while loading shared libraries: libsqlplus.so" Error and Solution

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)