We help IT Professionals succeed at work.

linux sqlplus to connect a remote oracle DB

Hello, I am using the sles11sp1 and l need a CLI tool to connect to a remote oracle DB. I have installed the following package I have sqlplus command available.
 rpm -qa | grep oracle
oracle-instantclient11.2-sqlplus-11.2.0.3.0-1
oracle-instantclient11.2-devel-11.2.0.3.0-1
oracle-instantclient11.2-basic-11.2.0.3.0-1
I have following data available:
Hostname on which DB is running
Port number: 1521
username
passowrd
and SID

Help me which command  I need to run to connect to remote DB. Thanks!
Comment
Watch Question

Kamaraj SubramanianApplication Support Analyst

Commented:
#!/bin/sh
sqlplus system/manager@prod_db <<ENDOFSQL
select sysdate from dual;
exit;
ENDOFSQL

Open in new window


The above is basic code to connect to oracle via sqlplus

Author

Commented:
SQL*Plus: Release 11.2.0.3.0 Production on Tue Dec 6 09:59:01 2011

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

ERROR:
ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA


Enter user-name: SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]
Enter user-name: Enter password:
ERROR:
ORA-12162: TNS:net service name is incorrectly specified


SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
Kamaraj SubramanianApplication Support Analyst

Commented:
before that, you need to set the environment variables.

normally variables will be defined in the .profile

check this post

http://dbamac.wordpress.com/2008/08/01/running-sqlplus-and-plsql-commands-from-a-shell-script/

Author

Commented:
I need the sqlplus CLI to access remote oracle database.
Kamaraj SubramanianApplication Support Analyst

Commented:
ok. you can install the below rpm for the sqlplus

oracle-instantclient11.2-sqlplus-11.2.0.3.0-1

Author

Commented:
already installed. look carefully at the question. Thanks.
Kamaraj SubramanianApplication Support Analyst

Commented:
you need to set the oracle environement variables.

then only your sqlplus command line will work

http://www.idevelopment.info/data/Oracle/DBA_tips/Unix/UNIX_4.shtml

Author

Commented:
Where can I configure tnsname.ora on linux and what is its configuration. To facilitate the command sqlplus. Thanks.
Kamaraj SubramanianApplication Support Analyst

Commented:
$ORACLE_HOME/network/admin/tnsnames.ora

http://www.orafaq.com/wiki/Tnsnames.ora

Author

Commented:
Thanks for the help, but I do not have Oracle installed locally. I just installed the instant client sqlplus. There are no such folders locally: $ ORACLE_HOME / network /
What is the alternative?
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
You need to manually create the network/admin folder and create a tnsnames.ora file under it.

The alternative is set an environment variable TNS_ADMIN pointing to the folder with the tnsnames.ora file.

Author

Commented:
Thank you, it worked.