Search notes:

Oracle: Database Link

A database link allows to access objects that are stored in other databases.
If the other database is not an Oracle database system, they must be accessed with Oracle Heterogeneous Services.

Closing/opening database links

begin

  for open_db_link in (
    select
      db_link,
      in_transaction
    from
      v$dblink
  ) loop

    if open_db_link.in_transaction <> 'NO' then
       dbms_output.put_line('Cannot close db link ' || open_db_link.db_link || ' as it is in a transaction.');
    else

       execute immediate 'alter session close database link ' || open_db_link.db_link;
       dbms_output.put_line('db link ' || open_db_link.db_link || ' was closed.');

    end if;

  end loop;

end;
/
Github repository Oracle-Patterns, path: /SQL/alter/session/close-open-database-link.sql

Executing a PL/SQL procedure in the remote database

select
  func_name @ link_name('param one', 'param two')
from
  dual;
Github repository Oracle-Patterns, path: /DatabaseObjects/Database-Links/function.sql

Executing a DDL statement in the remote database

dbms_utility.exec_ddl_statement allows to execute a DDL statement on a remote database via a database link:
begin
   dbms_utility.exec_ddl_statement@remote_db('create table t1 (id number)');
end;
/

Execution plans

If a statement can be run completely on the remote database, dbms_xplan.display() adds the note fully remote statement.
explain plan for
select count(*) from xyz@db_far_away;
select * from dbms_xplan.display();
----------------------------------------------------------------------------------------
| Id  | Operation              | Name         | Rows  | Cost (%CPU)| Time     | Inst   |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT REMOTE|              |     1 | 12034  (14)| 00:00:01 |        |
|   1 |  SORT AGGREGATE        |              |     1 |            |          |        |
|   2 |   INDEX FAST FULL SCAN | XYZ_IX       |    33M| 12034  (14)| 00:00:01 | XINST~ |
----------------------------------------------------------------------------------------
Note
-----
   - fully remote statement

See also

The driving_site SQL hint.
Interestingly, for me, at least, a database link is not an Oracle object.
sysdate@!
The execution plan operator remote.
Data links in the multitenant architecture.
DBA_DB_LINKS, v$dblink
The error messages
The init parameter open_links

Index