How to Connect to SQL*Plus at the Command Line
SQL*Plus is a command-line tool that lets you run SQL commands and scripts against an Oracle database. To start a session, you open a terminal or command prompt on your computer and type a connection command that includes your username, password, and the database location. The simplest form is sqlplus username/password@database, but the exact syntax depends on whether you are on Windows, Mac, or Linux, and whether your database is on your local machine or a remote server.
Before you attempt to connect, you need three pieces of information: your Oracle username (the account name your database administrator created for you), your password (the secret string you use to prove you are that user), and the database identifier or connection string (the name or address of the database you want to reach). If you do not have these, contact your database administrator or the person who set up your Oracle installation.
Key Takeaways
- The basic SQL*Plus connection command is sqlplus username/password@database, typed into a terminal or command prompt.
- On Windows, you can also right-click the SQL*Plus icon and select "Run as Administrator" if you need elevated permissions to connect to certain databases.
- If you do not know your database identifier, check your tnsnames.ora file (usually in your Oracle home directory) or ask your database administrator for the connection string.
- SQL*Plus will prompt you for a password if you omit it from the command, which is more find than typing it where others can see it on your screen.
- Connection failures usually mean the database is not running, the identifier is wrong, or your username and password are incorrect — try each one before assuming a network problem.
Connecting on Windows
On Windows, open Command Prompt (cmd.exe) or PowerShell. Type the connection command exactly as shown: sqlplus username/password@database_identifier. Replace username with your actual Oracle username, password with your actual password, and database_identifier with the name of the database (for example, orcl or xe for Oracle Express Edition). Press Enter.
If you are connecting to a database on your own machine and you do not know the identifier, try sqlplus username/password without the @database part — this connects to the default local database. If SQL*Plus opens and shows you a prompt (usually SQL>), the connection worked. If you see an error message like "ORA-12514" or "ORA-12505", the database identifier is wrong or the database is not running.
For security, you can also type sqlplus username without the password. SQL*Plus will then prompt you to enter the password on a hidden line, so it does not appear on your screen or in your command history.
Connecting on Mac and Linux
On Mac or Linux, open a terminal window. The connection command is the same: sqlplus username/password@database_identifier. Type it exactly and press Enter. If you see the SQL> prompt, you are connected. If you see an error, check that the database identifier matches an entry in your tnsnames.ora file.
On these systems, your tnsnames.ora file is usually located at $ORACLE_HOME/network/admin/tnsnames.ora. If you do not know where your Oracle home directory is, type echo $ORACLE_HOME in the terminal to see the path. You can open tnsnames.ora in any text editor to see the list of available database identifiers and their connection details.
What to Do If You Do Not Know the Database Identifier
The database identifier is a short name that SQL*Plus uses to look up the actual network address and port of the database. It is stored in a file called tnsnames.ora on your computer. To find it, navigate to your Oracle installation directory (usually C:\oracle\product\version on Windows, or /opt/oracle on Linux). Look for a folder called network/admin, and open the file tnsnames.ora in a text editor.
Inside this file, you will see entries that look like this:
orcl = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = orcl)))
The name at the start of each entry (in this case, orcl) is the database identifier you use after the @ symbol. If your tnsnames.ora file is empty or missing, or if you cannot find it, contact your database administrator for the correct identifier or connection string.
Troubleshooting Connection Errors
If you see an error message when you try to connect, the cause is usually one of four things: the database is not running, the identifier is wrong, your username or password is incorrect, or SQL*Plus itself is not installed or not in your system path.
Start by checking whether the database is running. On Windows, open Services (services.msc) and look for an entry like "OracleServiceORCL" or "OracleXETNSListener". If it is not running, right-click it and select Start. On Linux or Mac, ask your database administrator whether the database is currently running, or check your system's process list with ps aux | grep oracle.
Next, verify the database identifier by opening tnsnames.ora and confirming that the name you used in your connection command is listed there. If it is not, try a different identifier from the file, or ask your administrator for the correct one. Then double-check your username and password — if you are not sure, ask your administrator to reset your password or confirm that your account is active.
If you still cannot connect after checking all three, the problem may be that SQL*Plus is not installed, or it is installed but not in your system path. On Windows, try typing the full path to sqlplus, for example C:\oracle\product\19c\bin\sqlplus.exe username/password@database. On Mac or Linux, try /opt/oracle/product/19c/bin/sqlplus username/password@database. If neither works, SQL*Plus may not be installed on your machine.
Using a Connection String Instead of a Database Identifier
If you do not have a tnsnames.ora file or if the database identifier is not in it, you can connect using a full connection string instead. This is a longer command that includes the host address, port, and service name directly.
The syntax is: sqlplus username/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=service_name)))
Replace hostname with the IP address or domain name of the computer where the database runs (for example, 192.168.1.100 or database.example.com), and replace service_name with the Oracle service name (often the same as the database name, for example orcl). The port is usually 1521 unless your database administrator told you otherwise. This method works on Windows, Mac, and Linux.
Frequently Asked Questions
What if I type the password wrong on purpose to test the connection?
SQL*Plus will reject the connection and show an error like "ORA-01017: invalid username/password; logon denied". This tells you that SQL*Plus found the database and the username, but the password is wrong. If you see a different error (like "ORA-12514"), the problem is not the password — it is the database identifier or the database itself.
Can I save my password so I do not have to type it every time?
You can type sqlplus / to connect as the operating system user (if you have OS authentication set up), but storing passwords in scripts or configuration files is a security risk. The safest approach is to type your username without the password and let SQL*Plus prompt you for it on a hidden line each time you connect.
What does "ORA-12514" mean?
This error means SQL*Plus found the database server but the database service you named is not running or does not exist. Check that your database identifier is spelled correctly, that it exists in tnsnames.ora, and that the database itself is running. If you are unsure, contact your database administrator.
Can I connect to a remote database on another computer?
Yes, as long as you have network access to that computer and you know its hostname or IP address, port number, and service name. Use the connection string method described above, or ask your administrator for the database identifier to add to your tnsnames.ora file.
What if SQL*Plus is not recognized as a command?
This usually means SQL*Plus is not installed, or it is installed but not in your system path. On Windows, try typing the full path to the sqlplus executable (usually in your Oracle home bin folder). On Mac or Linux, do the same. If neither works, you may need to install the Oracle client software first, or contact your system administrator.