6.7 Connecting to the Database
There are several methods for connecting to Oracle Database.
Table 6-1 Database Connection Methods and Syntax
Type of Connection | Connection Syntax | Description |
---|---|---|
From the command line |
The general form of connecting an application to a database server from the command line is:
You are prompted to enter your password which is encrypted. For example: SQLPLUS system@sales
Enter password: |
Most Oracle tools can use the operating system command line to connect, and some provide alternatives. |
From a login screen |
|
Some tools provide a login screen as an alternative form to log in. A user can log in to a database server by identifying both the user name and connect identifier in the user name field of the tool login screen, and entering the password in the password field. |
From a 3GL application |
exec sql connect : In the preceding connection request, :username and :password are 3GL variables that can be set within the program either statically or by prompting the user. When connecting to a database server, the value of the :username variable is in the form:
The :password variable contains the password for the database account to which you are connecting. |
Applications written in 3GL, such as OCI and pre-compilers, are used by middle-tier and database application developers for direct database access from a client program. |
From within SQL*Plus |
SQLPLUS /nolog
SQL> CONNECT For example: SQLPLUS /nolog
SQL> CONNECT scott@serverx
Enter password: In the preceding commands, username and password are the database user and password, and net_service_name is the network service name. |
Some Oracle tools have commands for database connections to allow an alternative user name to be specified without leaving the tool. Other Oracle tools use slightly different methods specific to their function or interface. For example, Oracle CDE tools use login buttons with fields for the user name, password, and remote database ID. |
Using |
|
Use this parameter to specify the complete path to the Kerberos credentials cache file for the Kerberos principal ( If you are using Kerberos authentication to connect to a database, then specifying the complete path to the credential cache using
|
Using |
|
This parameter is used to specify Kerberos principals for a database client. This is an optional parameter. However, if you use this parameter, then ensure that the |
Using IAM database password verifier authentication |
SQLPLUS /nolog SQL> CONNECT username@net_service_name Enter password: password In this connection request, username is the IAM user name, net_service_name is the network service name, and password is the IAM database password. An IAM user can connect through a database proxy user account using password-based proxy authentication: SQLPLUS [user1]/password123\!@cdb1_pdb2 SQL> SHOW USER; select sys_context('USERENV','AUTHENTICATION_METHOD') from dual; select sys_context('USERENV','PROXY_USER') from dual; select sys_context('USERENV','CURRENT_USER') from dual; |
If you have configured Oracle Cloud Infrastructure (OCI) Identity and Access Management (IAM) for user authentication and authorization, then IAM users can connect to OCI Database as a Service (DBaaS) using the IAM user name and IAM database password. With this connection method, an IAM database password verifier (an encrypted hash of password) is retrieved from IAM to authenticate users. This IAM database password is different from the OCI console password. An IAM user can set this password from the OCI console (watch the Create an OCI IAM Password video). After you are granted the required authorization, you can log in from any supported database client using on-premise client applications, such as SQL*Plus. Use of IAM user name and IAM database password with the IAM database verifier is the default configuration, and you do not need to set any additional parameters for the client. However, if You can configure client connections (typically middle-tier environments) to use proxy authentication. In this case, you can alter an existing IAM user with necessary permissions to connect through a proxy database user account by using password-based proxy authentication. The proxy user session has all the privileges granted to the IAM user. |
Using IAM token-based authentication (bearer token) |
SQLPLUS /nolog
SQL> CONNECT /@connect_identifier The
You can use the optional
|
If you have configured IAM for user authentication and authorization, then IAM users can use an IAM database token ( You can configure the database client to request the An IAM user can set this IAM database password from the OCI console (watch the Create an OCI IAM Password video). The database client retrieves the token directly from the OCI IAM endpoint. You must set additional parameters so that the database client can find the IAM endpoint along with additional metadata. The additional parameters are When an IAM user logs in with the IAM user name and IAM database password using You can specify these parameters in the |
Using IAM token-based authentication (PoP token) |
SQLPLUS /nolog
SQL> CONNECT /@connect_identifier The
You can use the optional
An IAM user can connect through a database proxy user account using token-based proxy authentication:
|
If you have configured IAM for user authentication and authorization, then IAM users can use an IAM database token ( You can use one of the IAM user credentials, such as API-key, security token, resource principal, service principal, instance principal, or delegation token (delegation token is available only in the Cloud Shell) to retrieve the A client application can send a connection request in one of the following ways:
You can specify these parameters in the You can configure client connections to use proxy authentication. In this case, you can alter an IAM user with necessary permissions to connect through a proxy database user account by using token-based proxy authentication. The proxy user session has all the privileges granted to the IAM user. |
Using Azure token-based authentication |
SQLPLUS /nolog
SQL> CONNECT /@connect_identifier The If the token file is named
If the token file name is different from
|
If you have configured Microsoft Entra ID (previously called Microsoft Azure Active Directory) for user authentication and authorization, then Azure users can use the Entra ID OAuth2 access token to connect to an Oracle Database. This access token is a bearer token with an expiration time and scope, and follows the OAuth2.0 standard with Entra ID extensions. The The You specify the You can request the tokens from tools and scripts run on Linux, Microsoft PowerShell, or other environments. You can also request these tokens programmatically using the Microsoft SDKs. A client application can send a connection request in one of the following ways:
|
Note:
If you have configured IAM token-based authentication, then you can enable the database client to directly retrieve the db-token
with IAM Single-Sign On (SSO) credentials using OCI authentication flows, such as OCI_INTERACTIVE
, OCI_API_KEY
, OCI_INSTANCE_PRINCIPAL
, OCI_DELEGATION_TOKEN
, and OCI_RESOURCE_PRINCIPAL
.
Similarly, if you have configured Azure token-based authentication, then you can enable the database client to directly retrieve the access token with Azure SSO credentials using authentication flows, such as AZURE_INTERACTIVE
, AZURE_SERVICE_PRINCIPAL
, AZURE_MANAGED_IDENTITY
, and AZURE_DEVICE_CODE
.
This feature is available in environments that use JDBC-thin clients, ODP.NET Core classes, or ODP.NET Managed Driver classes. To configure this feature for JDBC-thin clients, see Oracle Database JDBC Developer's Guide and for ODP.NET, see Oracle Data Provider for .NET Developer's Guide.
Related Topics
Parent topic: Quick Start to Oracle Net Services