Purpose
You can use this statement to create a database link (dblink) to access objects in a remote database.
The current OceanBase Database version allows you to use the SELECT statement to query data in a remote data source through @dblink. You can specify multiple data sources in the same SELECT statement, including local and remote data sources. For more information, see SIMPLE SELECT.
To create a database link, you must have the CREATE DATABASE LINK system privilege. You must also have the CREATE SESSION system privilege on the database.
Syntax
CREATE DATABASE LINK dblink_name CONNECT TO user_name@tenant_name IDENTIFIED BY password OB HOST 'ip:port' [CLUSTER cluster_name] ;
Parameters
| Parameter | Description |
|---|---|
| dblink_name | The name of the database link to access. |
| user_name | The username of the remote database. |
| tenant_name | The tenant name of the remote database. |
| password | The password corresponding to the username of the remote database. |
| OceanBase | Sets the remote database type to OceanBase Database. OceanBase Database is the default remote database type. |
| ip | The IP address of the remote database. If the remote database type is OceanBase Database, you can set the IP address to the IP address of an ODP in the cluster or to the IP address of an OBServer in the cluster. If you set the IP address of the remote database to the IP address of an OBServer, the local database and the specified OBServer must be able to communicate with each other over network. |
| port | The port number of the remote database. If the remote database type is OceanBase Database, you can set the port number to the port number of an ODP in the cluster or to the port number of an OBServer in the cluster. If you set the port number of the remote database to the port number of an OBServer, the local database and the specified OBServer must be able to communicate with each other over network. |
Examples
Create, in the default oracle tenant, a database link for which the remote database type is OceanBase Database.
obclient> CREATE DATABASE LINK my_link CONNECT TO 'ob_link'@oracle IDENTIFIED BY a***f OB HOST '10.0.0.0:8080';
Query OK, 1 row affected