Create Database Links to Non-Oracle AI Databases with Oracle-Managed Heterogeneous Connectivity
Autonomous AI Database support for Oracle-managed heterogeneous connectivity makes it easy to create database links to non-Oracle databases.
When you use database links with Oracle-managed heterogeneous connectivity, Autonomous AI Database configures and sets up the connection to the non-Oracle database.
Note: With Oracle-managed heterogeneous connectivity the support is for query-only connections on the remote database. That is, updates are not supported when using Oracle-managed heterogeneous connectivity.
The following are the prerequisites for using Oracle-managed heterogeneous connectivity with Autonomous AI Database:
-
When the target database is on a public endpoint, database must be configured to allow incoming SSL/TLS connections with CA signed certificates.
Oracle-managed heterogeneous connectivity supports connections to target database services on private endpoints (for example you can connect to Oracle MySQL Database Service when the service is on a private endpoint). When you connect to a non-oracle database with Oracle-managed heterogeneous connectivity on a private endpoint, the connection uses TCP protocol and it does not require SSL/TLS to be configured on the target database.
See Create Database Links to Oracle MySQL on a Private Endpoint with Oracle-Managed Heterogeneous Connectivity for more information.
-
When the target database is on private endpoint and configured to enforce SSL based connections, use the
gateway_paramsparameter calledenable_ssland set it toTRUE. For example:gateway_params => JSON_OBJECT( 'db_type' value 'snowflake', 'enable_ssl' value true)See CREATE_DATABASE_LINK Procedure for more information.
-
When the target database is on private endpoint and configured to enforce SSL based connections, use the
gateway_paramsparameter calledenable_ssland set it to true.See CREATE_DATABASE_LINK Procedure for more information.
To create database links to a non-Oracle database using Oracle-managed heterogeneous connectivity, do the following:
-
On Autonomous AI Database create credentials to access the target database. The
usernameandpasswordyou specify withDBMS_CLOUD.CREATE_CREDENTIALare the credentials for the target database used within the database link.For example:
BEGIN DBMS_CLOUD.CREATE_CREDENTIAL( credential_name => 'AWS_REDSHIFT_LINK_CRED', username => 'nick', password => 'password' ); END; /This operation stores the credentials in the database in an encrypted format. You can use any name for the credential name. Supplying the
credential_nameparameter is required.To access Google Analytics, Google BigQuery, Google Drive, Youtube, ServiceNow, or Microsoft SharePoint with OAuth2, the credential must include the
paramsparameter with the valuegcp_oauth2.For example:
BEGIN DBMS_CLOUD.CREATE_CREDENTIAL( credential_name => 'SERVICENOW_OAUTH', params => JSON_OBJECT( 'gcp_oauth2' value JSON_OBJECT( 'client_id' value '*CLIENT_ID*', 'client_secret' value '*CLIENT_SECRET*', 'refresh_token' value '*Refresh_Token*'))); END; /See CREATE_CREDENTIAL Procedure for more information.
-
Create the database link to the target database using
DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK.For example, to create a database link to AWS Redshift:
BEGIN DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK( db_link_name => 'AWSREDSHIFT_LINK', hostname => '*example.com*', port => 5439, service_name => '*example_service_name*', credential_name => 'AWS_REDSHIFT_LINK_CRED', gateway_params => JSON_OBJECT('db_type' value 'awsredshift'), ssl_server_cert_dn => NULL); END; /The
service_nameis the database name of the non-Oracle database.The
gateway_params db_typevalue that you supply must be one of the supported values:db_type Value Database Type awsredshiftAmazon Redshift azureMicrosoft SQL Server
Azure SQL
Azure Synapse Analytics
boxBox cassandraApache Cassandra databricksDatabricks db2IBM Db2 google_analyticsGoogle Analytics google_bigqueryGoogle BigQuery google_driveGoogle Drive hiveApache Hive mongodbMongoDB mysqlMySQL
The
VECTORdata type is not supported fordb_type=mysql. See The VECTOR Type for more information.mysql_communityMySQL Community Edition postgresPostgreSQL salesforceSalesforce servicenowServiceNow sharepointMicrosoft SharePoint snowflakeSnowflake youtubeYouTube Autonomous AI Database automatically configures and handles the secure connection to a target database and your connections are end-to-end encrypted. Oracle-managed heterogeneous connectivity is preconfigured with a wallet that contains most of the common trusted root and intermediate SSL certificates. Thus,
NULLmust be provided as the value for thessl_server_cert_dnparameter.To ensure security when using database links with Oracle-managed heterogeneous connectivity, the connection port is restricted and must have SSL/TLS enabled. You specify the target database port with the
portparameter.See Oracle-Managed Heterogeneous Connectivity Database Types and Ports for the list of supported non-Oracle database types.
The
HETEROGENEOUS_CONNECTIVITY_INFOview provides information on supported Oracle Heterogeneous Connectivity types and shows a PL/SQL code sample for each supported type. See Access Heterogeneous Connectivity Information and Samples for more information.When you specify the
gateway_paramsparameter, for somedb_typevalues, additionalgateway_paramsparameters are supported:db_typeValueSupported Gateway Parameters with Specified db_type azureWhen the
db_typevalue isazurethere are two optional parameters,auth_methodanddomainto support NTLM/AD authentication.When NTLMv2 is configured, set
auth_method=10and setdomainto the Windows domain value.To use an Azure Active Directory password, set
auth_method=13. Do not useauth_method=13to access an Oracle on-premises Database.See Microsoft SQL Server Authentication Method for more information.
google_analyticsWhen the
db_typevalue isgoogle_analyticsthehostnameis not used and you can provide value such asexample.com.For
db_typegoogle_analytics, the credential must be an OAuth type credential using theparamsparameter withgcp_oauth2values specified (client_id,client_secret, andrefresh_token). See CREATE_CREDENTIAL Procedure for more information.google_bigqueryWhen
db_typeisgoogle_bigquery, the parameterprojectis valid. This parameter specifies the project name ongoogle_bigqueryand is required.When the
db_typevalue isgoogle_bigquerythehostnameis not used and you can provide value such asexample.com.For
db_typegoogle_bigquery, the credential must be an OAuth type credential using theparamsparameter withgcp_oauth2values specified (client_id,client_secret, andrefresh_token). See CREATE_CREDENTIAL Procedure for more information.google_driveFor
db_typegoogle_drive, the credential you supply withDBMS_CLOUD_ADMIN.CREATE_DATABASE_LINKmust be an OAuth type credential using theparamsparameter withgcp_oauth2values specified (client_id,client_secret, andrefresh_token).To connect to Google Drive and get data you must supply the gateway parameters
directory_nameandfile_name. These parameters specify a model file (auto REST file) that maps the JSON response to the relational model. The model file specifies the endpoints, table mapping, and HTTP response code for processing the JSON response. See Model file syntax and Example Model file for more information.When you use
gateway_paramsparameter withdb_typegoogle_driveyou must supply thegateway_paramsparameterdb_typewith the value'google_drive'and thedirectory_nameandfile_nameparameters, along with OAuth type credentials:The
directory_nameparameter specifies the directory with the REST config file. You could create this directory as follows:create or replace directory google_drive_dir as 'GOOGLE_DRIVE_DIR';Obtain and download the auto REST file to the specified directory. For example:
exec DBMS_CLOUD.get_object('google_drive_dir_cred', 'https://objectstorage.<...>/google_drive.rest','GOOGLE_DRIVE_DIR');Set the
file_namevalue to the name of the auto REST file you downloaded, "google_drive.rest". Then you can use the REST config file with OAuth 2.0.hiveWhen db_typeishive, the parameterhttp_pathis valid. This parameter specifies the HttpPath value, if required, to connect to the Hive instance.salesforceWhen you use
gateway_paramsparameter withdb_typesalesforce, you must supply thesecurity_tokenoption. The security token is a case-sensitive alphanumeric code.See Reset Your Security Token for more information.
When you use
gateway_paramsparameter withdb_typesalesforce, you must supply the correcthostnameparameter.Salesforce provides two forms of URLs for the Salesforce service account:
xxxx.develop.lightning.force.comform of URLxxxxmy.salesforce.comform of URL as shown under the View profile tab.
Oracle-Managed Heterogeneous Connectivity only supports the
xxxxmy.salesforce.comform of URL for thehostnameparameter value.servicenowTo connect to ServiceNow and get data you must supply the gateway parameters
directory_nameandfile_name. These parameters specify a model file (REST config file) that maps the JSON response to the relational model. The model file specifies the endpoints, table mapping, and HTTP response code for processing the JSON response. See Model file syntax and Example Model file for more information.When you use
gateway_paramsparameter withdb_typeservicenowthere are two supported options:Basic Authentication: you must supply the
gateway_paramsparameterdb_typewith the value'servicenow', and supply thedirectory_nameandfile_nameparameters along with username/password type credentials.OAuth 2.0 Authentication: you must supply the
gateway_paramsparameterdb_typewith the value'servicenow', and thedirectory_name,file_name, andtoken_uriparameters, along with OAuth type credentials.For OAuth 2.0 authentication with
db_typeservicenow, the credential must be an OAuth type credential using theparamsparameter withgcp_oauth2values specified specified (client_id,client_secret, andrefresh_token). See CREATE_CREDENTIAL Procedure for more information.
The
directory_nameparameter specifies the directory with the ServiceNow REST config file. You could create this directory as follows:create or replace directory servicenow_dir as 'SERVICENOW_DIR';Obtain and download the ServiceNow REST config file to the specified directory. For example:
exec DBMS_CLOUD.get_object('servicenow_dir_cred', 'https://objectstorage.<...>/servicenow.rest','SERVICENOW_DIR');Set the
file_namevalue to the name of the REST config file you downloaded, "servicenow.rest".Then you can use the ServiceNow REST config file with either basic authentication or OAuth2.0. See HETEROGENEOUS_CONNECTIVITY_INFO View for samples.
sharepointWhen you use
gateway_paramsparameter withdb_typesharepoint, also specify values forauth_uri,scope,service_url, andtoken_uri.For
db_typesharepoint, the credential you supply withDBMS_CLOUD_ADMIN.CREATE_DATABASE_LINKmust be an OAuth type credential using theparamsparameter withgcp_oauth2values specified (client_id,client_secret, andrefresh_token). See CREATE_CREDENTIAL Procedure for more information. Generate therefresh_tokenfor tenant_id.sharepoint.com/.defaultoffline_access. See the following for more information: Determine the scope and OAuth 2.0 authentication.Set values for
gateway_paramsfordb_typesharepoint:auth_uri: Set theauth_urifrom Azure. See Obtain application client information and endpoints for more information.scope: Set the scope. See Connection option descriptions for more information.service_url: Set theservice_url. See Service URL for more information.token_uri: Get thetoken_urifrom Azure. See Obtain application client information and endpoints for more information.
snowflakeWhen you use
gateway_paramsparameter withdb_typesnowflake, use the Snowflake account identifier as thehostnameparameter. In this case, the driver addssnowflakecomupting.com, so you do not pass this part of the hostname explicitly. To find your Snowflake account identifier, see Account Identifier Formats by Cloud Platform and Region.For example: for the Snowflake account:
https://example-marketing_test_account.snowflakecomputing.comSet the
hostnamevalue to"example-marketing_test_account".When the
db_typeisSNOWFLAKE, the optional parameters:role,schema, andlakehouseare valid. These values specify a different schema, role, or lakehouse value, other than the default. For example:gateway_params => JSON_OBJECT( 'db_type' value 'snowflake', 'role' value 'ADMIN', 'schema' value 'PUBLIC', 'lakehouse' value 'TEST' )youtubeTo connect to YouTube and get data, you must supply the parameters
directory_nameandfile_name. These parameters specify a model file (REST config file) that maps the JSON response to the relational model. The model file specifies the endpoints, table mapping, and HTTP response code for processing the JSON response. See Model file syntax and Example Model file for more information.For
db_typeyoutube, the credential must be an OAuth type credential using theparamsparameter withgcp_oauth2values specified (client_id,client_secret, andrefresh_token). See CREATE_CREDENTIAL Procedure for more information.The
directory_nameparameter specifies the directory with the youtube REST config file.For example, to create this directory and add the required contents:
Create a directory on the Autonomous AI Database instance:
create or replace directory youtube_dir as 'YOUTUBE_DIR';Obtain and download the auto rest REST config file to the specified directory. For example:
exec DBMS_CLOUD.get_object('youtube_dir_cred', 'https://objectstorage.<...>/youtube.rest','YOUTUBE_DIR');Set the
file_namevalue to the name of the REST config file you downloaded,'youtube.rest'.
Then you can use the REST config file with OAuth2.0. See HETEROGENEOUS_CONNECTIVITY_INFO View for samples.
boxTo connect to Box and get data, you must supply the parameters
directory_nameandfile_name. These parameters specify a model file (REST config file) that maps the JSON response to the relational model. The model file specifies the endpoints, table mapping, and HTTP response code for processing the JSON response. See Model file syntax and Example Model file for more information.For
db_typebox, the credential must be an OAuth type credential using theparamsparameter withgcp_oauth2values specified (client_id,client_secret, andrefresh_token). See CREATE_CREDENTIAL Procedure for more information.The
directory_nameparameter specifies the directory with the box REST config file.For example, to create this directory and add the required contents:
Create a directory on the Autonomous AI Database instance:
create or replace directory box_dir as 'BOX_DIR';Obtain and download the auto rest REST config file to the specified directory. For example:
exec DBMS_CLOUD.get_object('box_dir_cred', 'https://objectstorage.<...>/box.rest','BOX_DIR');Set the
file_namevalue to the name of the REST config file you downloaded,'box.rest'.
Then you can use the REST config file with OAuth2.0. See HETEROGENEOUS_CONNECTIVITY_INFO View for samples.
databricksTo connect to Databricks and get data, you must supply the parameters
directory_nameandfile_name. These parameters specify a model file (REST config file) that maps the JSON response to the relational model. The model file specifies the endpoints, table mapping, and HTTP response code for processing the JSON response. See Model file syntax and Example Model file for more information.For
db_typebox, the credential must be an OAuth type credential using theparamsparameter withgcp_oauth2values specified (client_id,client_secret, andrefresh_token). See CREATE_CREDENTIAL Procedure for more information.The
directory_nameparameter specifies the directory with the box REST config file.For example, to create this directory and add the required contents:
Create a directory on the Autonomous AI Database instance:
create or replace directory databricks_dir as 'BOX_DIR';Obtain and download the auto rest REST config file to the specified directory. For example:
exec DBMS_CLOUD.get_object('databricks_dir_cred', 'https://objectstorage.<...>/databricks.rest','DATABRICKS_DIR');Set the
file_namevalue to the name of the REST config file you downloaded,'databricks.rest'.Then you can use the REST config file with OAuth2.0. See HETEROGENEOUS_CONNECTIVITY_INFO View for samples.
See CREATE_DATABASE_LINK Procedure for more information.
-
Use the database link to access data on the target database.
For example:
SELECT count(*) FROM sales@AWSREDSHIFT_LINKThe table name you specify in a
SELECTstatement must be properly quoted as an identifier, this applies to Google BigQuery, MySQL, and PostgreSQL. For example:SELECT count(*) FROM "sales"@GOOGLE_BIGQUERY_LINKNote:
For the credentials you create in Step 1, the target database credentials, if the password of the target user changes you can update the credential that contains the target user’s credentials as follows:
BEGIN DBMS_CLOUD.UPDATE_CREDENTIAL ( credential_name => 'AWS_REDSHIFT_LINK_CRED', attribute => 'PASSWORD', value => 'password'); END; /Where password is the new password.
After this operation, the existing database links that use this credential continue to work without having to drop and recreate the database links.
For additional information, see:
-
Supported SQL Syntax and Functions in Oracle AI Database Gateway for ODBC User's Guide
-
Create Database Links to Oracle MySQL on a Private Endpoint with Oracle-Managed Heterogeneous Connectivity
Autonomous AI Database support for Oracle-managed heterogeneous connectivity makes it easy to create database links to Oracle MySQL Database Service on a private endpoint. When you use database links with Oracle-managed heterogeneous connectivity, Autonomous AI Database configures and sets up the connection to the Oracle MySQL Database Service.
The following are prerequisites to use Oracle-managed heterogeneous connectivity with Oracle MySQL Database Service on a private endpoint:
-
Create a DNS name using private DNS Zone pointing to private IP of your Oracle MySQL Database Service in your VCN. See Private DNS.
-
Create an Autonomous AI Database with a Private Endpoint on same subnet.
-
Configure the VCN for the Oracle MySQL Database Service to allow incoming connections on port 3306.
To create database links to a Oracle MySQL Database Service on a private endpoint using Oracle-managed heterogeneous connectivity, do the following:
-
On Autonomous AI Database create credentials to access the Oracle MySQL Database Service. The
usernameandpasswordyou specify withDBMS_CLOUD.CREATE_CREDENTIALare the credentials for the Oracle MySQL Database Service used within the database link.Note: Supplying the
credential_nameparameter is required.For example:
BEGIN DBMS_CLOUD.CREATE_CREDENTIAL( credential_name => 'MYSQL_LINK_CRED', username => 'NICK', password => 'password' ); END; /This operation stores the credentials in the database in an encrypted format. You can use any name for the credential name.
-
Create the database link to the Oracle MySQL Database Service using
DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK.For example, to create a database link:
BEGIN DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK( db_link_name => 'MYSQL_LINK', hostname => '*mysql.example.com*', port => '3306', service_name => '*mysql.example_service_name*', ssl_server_cert_dn => NULL, credential_name => 'MYSQL_LINK_CRED', private_target => TRUE, gateway_params => JSON_OBJECT('db_type' value 'mysql')); END; / -
Use the database link to access data on the target database.
For example:
SELECT count(*) FROM sales@MYSQL_LINKNote:
For the credentials you create in Step 1, the target database credentials, if the password of the target user changes you can update the credential that contains the target user’s credentials as follows:
BEGIN DBMS_CLOUD.UPDATE_CREDENTIAL ( credential_name => 'MYSQL_LINK_CRED', attribute => 'PASSWORD', value => 'password'); END; /Where password is the new password.
After this operation, the existing database links that use this credential continue to work without having to drop and recreate the database links.
For additional information, see:
-
Supported SQL Syntax and Functions in Oracle AI Database Gateway for ODBC User's Guide
-
-
Oracle-Managed Heterogeneous Connectivity Database Types and Ports
Shows the non-Oracle databases that you can connect to from Autonomous AI Database with Oracle-managed heterogeneous connectivity, and lists the supported port value for each database type. Also provides a link where you can see the supported database versions for each database type.
Note: Oracle uses Progress DataDirect connectors. The Database Support column provides links to the Progress website where you can find the supported database versions for each database type.
| Database Type | db_type Value | Required Port | Database Support |
|---|---|---|---|
| Amazon Redshift | awsredshift |
5439 | Amazon Redshift Supported Versions |
Azure SQL Microsoft SQL Server Azure Synapse Analytics |
azure |
1433 | |
| Apache Cassandra | cassandra |
9042 | Cassandra Supported Versions |
| Apache Hive | hive |
443 | Hive Supported Versions |
| Google Analytics | google_analytics |
443 | Google Analytics Supported Versions |
| Google BigQuery | google_bigquery |
443 | Google BigQuery Supported Versions |
| Google Drive | google_drive |
443 | Google Drive Supported Versions |
| Apache Hive | hive |
443 | Hive Supported Versions |
IBM Db2 11.5.6 or greater IBM Db2 11.5.5 or less |
db2 |
25000 50000 |
IBM Db2 Supported Versions |
| Microsoft SharePoint | sharepoint |
443 | Microsoft SharePoint Supported Versions |
| MongoDB | mongodb |
27017 | MongoDB Supported Versions |
| MySQL | mysql |
3306 | MySQL Supported Versions |
| MySQL Community Edition | mysql_community |
3306 | |
| PostgreSQL | postgres |
5432 | PostgreSQL Supported Versions |
| Salesforce | salesforce |
19937 | Salesforce Supported Versions |
| ServiceNow | servicenow |
443 | ServiceNow Supported Versions |
| Snowflake | snowflake |
443 | Snowflake Supported Versions |
| Youtube | youtube |
443 | Youtube Supported Versions |
| Box | box |
443 | VirtualBox Supported Versions |
| Databricks | databricks |
443 | Databricks Runtime release notes versions and compatibility |
Access Heterogeneous Connectivity Information and Samples
Oracle Autonomous AI Database provides heterogeneous connectivity information for database links to non-Oracle databases.
The HETEROGENEOUS_CONNECTIVITY_INFO view provides information on supported Oracle Heterogeneous Connectivity types and shows a PL/SQL code sample for each supported type.
For example:
SELECT * FROM HETEROGENEOUS_CONNECTIVITY_INFO WHERE DATABASE_TYPE = 'hive';
HETEROGENEOUS_CONNECTIVITY_INFO View
The HETEROGENEOUS_CONNECTIVITY_INFO view lists connectivity information and examples for connecting with PL/SQL using database links and Oracle Managed Heterogeneous Connectivity.
| Column | Datatype | Description |
|---|---|---|
DATABASE_TYPE |
VARCHAR2(32) |
Database type value used with gateway_params parameter. |
REQUIRED_PORT |
NUMBER |
Supported port values for the database type. |
DESCRIPTION |
CLOB |
Specifies a description for the DATABASE_TYPE. |
OPTIONAL_PARAMETERS |
VARCHAR2(1024) |
Specifies the valid optional parameters for the DATABASE_TYPE. |
SAMPLE_USAGE |
CLOB |
Shows sample PL/SQL usage for the DATABASE_TYPE. |