A2oz

How to Connect to an Oracle Database from the Command Prompt

Published in Database Administration 2 mins read

Connecting to an Oracle database from the command prompt is a common task for database administrators and developers. This process involves using the sqlplus command-line utility, which provides a powerful interface for interacting with the database. Here's how you can connect:

1. Open a Command Prompt Window

Open a command prompt window on your system. You can typically do this by searching for "cmd" in the Windows Start menu or using the terminal in macOS or Linux.

2. Use the sqlplus Command

Type the following command in the command prompt, replacing <username> with your Oracle database username and <password> with your password:

sqlplus <username>/<password>@<database_instance>
  • <database_instance>: This refers to the specific Oracle database instance you want to connect to. It can be a hostname, a service name, or a TNS alias.

For example, to connect to a database instance named "mydatabase" on the local machine:

sqlplus user/password@mydatabase

3. Connect to the Database

Press Enter. If your credentials are correct and the database instance is accessible, you'll be connected to the Oracle database. You'll see a prompt similar to:

SQL>

Now you can execute SQL commands and interact with the database.

4. Exit sqlplus

When you're finished, type exit and press Enter to disconnect from the database and close the sqlplus session.

Example:

Here's an example of connecting to a database using a TNS alias named "mydatabase_alias":

sqlplus user/password@mydatabase_alias

Additional Notes:

  • If you encounter errors, double-check your username, password, and database instance name.
  • You might need to configure your environment variables or network settings to connect successfully.
  • Oracle provides extensive documentation on sqlplus and connecting to databases. Refer to the official Oracle documentation for more detailed information and advanced options.

Related Articles