Oracle Database powers the most critical applications, regardless of the industry. Interacting with an Oracle Database requires a client tool that allows you to execute SQL commands and manage the database. One such tool is SQL*Plus, a powerful command line interface that comes bundled with Oracle Database installations.
SQL*Plus serves as a text-based interface, particularly useful for establishing direct interaction with the database. But how do you connect to your Oracle database using SQL*Plus? That’s what this article is all about. Spoiler alert – the process is actually pretty easy, only three steps to be exact.
Prerequisites for Connecting to Oracle Database Using SQL*Plus
Below are the prerequisites to ensure before you can use SQL*Plus to connect to an Oracle Database.
1. Oracle Database Installation: You must have Oracle Database installed on your system or have access to a remote Oracle Database server.
2. Oracle Client: If you will be connecting to a remote Oracle Database, we recommend having Oracle Client ready to run on your machine.
3. Oracle User Account: You need a valid Oracle user account with proper privileges to connect to a database. In this tutorial, we assume you already have your account set up.
How to Use SQL*Plus for Connecting to Oracle Database: Example
After taking the necessary actions described in the above section, follow these steps to connect to an Oracle Database using SQL*Plus:
Step 1: Open Command Prompt (Windows) or Terminal (Linux)
Make sure to have a command prompt or terminal window open on your PC. If you use Windows, we recommend using the ‘Run as administrator’ to open the command prompt window.
Step 2: Launch SQL*Plus
Run the following command to launch SQL*Plus on your system.
Replace the username and password with your Oracle Database credentials. The database_host should be the hostname of the IP address of the Oracle Database Server. Also, swap out the port with the correct port number for the Oracle Database listener, usually 1521. Lastly, enter the Oracle Database service name in the place for service_name.
You can also do this by first running the ‘sqlplus’ command and then entering the username and password when prompted.
Step 3: Start SQL*Plus
Press Enter, and SQL*Plus will automatically attempt to connect to your specified database. On establishing a successful connection, the SQL*Plus command prompt should appear, looking like this:
You are now connected to the Oracle database and can start executing SQL commands or PL/SQL scripts.
How do I disconnect from the Oracle Database using SQL*Plus?
Type ‘EXIT’ in the SQL*Plus command prompt and press Enter to disconnect from the Oracle Database and exit the session.
Is SQL*Plus the only tool to connect to Oracle Databases?
SQL*Plus is not the only tool for connecting to Oracle databases. Other tools like Oracle SQL Developer provide a GUI for easy management of the database.
How to pass SQL file to SQL*Plus?
Type @ followed by the SQL file. This command, however, searches for the file inside the current directory. So, change the directory where you saved the file.
You can connect to an Oracle Database using SQL*Plus and leverage its capabilities by following the steps mentioned in this article. If you face any issues while establishing the connection, feel free to ask in the comment section. Help should be on your way. Thanks for reading!