How do I default to the local database when logging in from the command line?

book

Article ID: 159753

calendar_today

Updated On:

Products

Data Loss Prevention Enforce

Issue/Introduction

When attempting to log into SQLPlus from the command line on a database server that contains one and only one database, it is necessary to provide the name of the local database in order to connect, rather than accepting the local database as the default.  ORA-12560 is encountered:

C:\Documents and Settings\Administrator>sqlplus protect

SQL*Plus: Release 10.2.0.4.0 - Production on Tue Feb 10 13:43:43 2009

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Enter password:

ERROR:ORA-12560: TNS:protocol adapter error

Resolution

Set the ORACLE_SID via My Computer > Properties > Advanced > Environment Variables. Add a new variable (or edit existing) by clicking New and supplying a variable name of ORACLE_SID and a value of whatever the database (service) name is as it appears in the tnsnames.ora file. Click OK when you are done.

When you log in from the command line again, the new variable will be picked up and you should get something similar to the following:

C:\Documents and Settings\Administrator>sqlplus protect

SQL*Plus: Release 10.2.0.4.0 - Production on Tue Feb 10 13:49:24 2009

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Enter password:

Connected to:Oracle Database 10g Release 10.2.0.4.0 - Production

SQL>

To connect to another database, provide the net service name as it appears in the tnsnames.ora file. Use the following example:

C:\Documents and Settings\Administrator>sqlplus [email protected]

SQL*Plus: Release 10.2.0.4.0 - Production on Tue Feb 10 13:49:24 2009

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Enter password:

Connected to:Oracle Database 10g Release 10.2.0.4.0 - Production

SQL>