Technology Encyclopedia Home >What is the Oracle database connection command?

What is the Oracle database connection command?

The Oracle database connection command is typically executed using SQL*Plus, a command-line tool provided by Oracle to interact with the database. The basic syntax for connecting to an Oracle database is:

sqlplus username/password@[//]host[:port][/service_name]

Explanation:

  • username: The database user account (e.g., scott).
  • password: The password for the user (e.g., tiger).
  • host: The hostname or IP address of the database server (e.g., localhost or 192.168.1.100).
  • port: The port number where the Oracle listener is running (default is 1521).
  • service_name: The Oracle service name (or SID for older versions).

Examples:

  1. Connecting to a local Oracle database (default port 1521, service name ORCL):

    sqlplus scott/tiger@//localhost:1521/ORCL
    

    or (older SID-based connection):

    sqlplus scott/tiger@//localhost:1521:ORCL
    
  2. Connecting without specifying the host (for local databases):

    sqlplus scott/tiger
    

    (This assumes the database is running locally and the environment is properly configured.)

  3. Using TNS (via tnsnames.ora configuration):
    If you have a TNS alias defined in tnsnames.ora, you can connect like this:

    sqlplus scott/tiger@ORCL_TNS
    

    (Where ORCL_TNS is the alias defined in the TNS configuration file.)

For Cloud-Based Oracle Databases (e.g., on Tencent Cloud):

If you're using an Oracle database hosted on Tencent Cloud Database (TencentDB for Oracle), the connection command remains similar, but you must ensure:

  • The public IP or private IP of the database instance is used.
  • The correct port (usually 1521) is open in the security group.
  • The username and password are correctly configured in the Tencent Cloud console.

Example for Tencent Cloud Oracle:

sqlplus admin/YourPassword@//your-database-ip:1521/ORCL

For secure connections, consider using SSL/TLS or VPN if the database is in a private network. Tencent Cloud also provides Database Connection Tools and PrivateLink for secure access.

If you prefer a GUI tool, SQL Developer (Oracle's official client) or Tencent Cloud Database Console can also be used to manage connections.