Nirm, I think you are right (as usual!) about the transaction preventing the DB Link from being closed. When I just rollback to the savepoint, there is still a transaction and I can’t close the link. When I rollback completely, I can close the link. What confuses me is, if there was no transaction before the savepoint, shouldn’t rolling back to the savepoint end the transaction? See below.
SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 30 08:22:55 2017
Copyright © 1982, 2014, Oracle. All rights reserved.
Last Successful login time: Thu Nov 30 2017 08:22:12 -06:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>
SQL> select decode(sys.dbms_transaction.local_transaction_id, null, ‘No’, ‘Yes’) as in_transaction
2 from dual;
IN_TRANSACTION
No
SQL>
SQL> savepoint DBLinkTest;
Savepoint created.
SQL>
SQL> select decode(sys.dbms_transaction.local_transaction_id, null, ‘No’, ‘Yes’) as in_transaction
2 from dual;
IN_TRANSACTION
Yes
SQL>
SQL> SELECT ‘Link Opened’ as Link_opened
2 from dual@“AZURE_12CR2_PLUG.CLOUDAPP.NET”;
LINK_OPENED
Link Opened
SQL>
SQL> select decode(sys.dbms_transaction.local_transaction_id, null, ‘No’, ‘Yes’) as in_transaction
2 from dual;
IN_TRANSACTION
Yes
SQL>
SQL> rollback to savepoint DBLinkTest;
Rollback complete.
SQL>
SQL> select decode(sys.dbms_transaction.local_transaction_id, null, ‘No’, ‘Yes’) as in_transaction
2 from dual;
IN_TRANSACTION
Yes
SQL>
SQL> exec DBMS_SESSION.CLOSE_DATABASE_LINK(‘AZURE_12CR2_PLUG.CLOUDAPP.NET’);
BEGIN DBMS_SESSION.CLOSE_DATABASE_LINK(‘AZURE_12CR2_PLUG.CLOUDAPP.NET’); END;
ERROR at line 1:
ORA-02080: database link is in use
ORA-06512: at “SYS.DBMS_SESSION”, line 191
ORA-06512: at line 1
SQL>
SQL> rollback;
Rollback complete.
SQL>
SQL> select decode(sys.dbms_transaction.local_transaction_id, null, ‘No’, ‘Yes’) as in_transaction
2 from dual;
IN_TRANSACTION
No
SQL>
SQL> exec DBMS_SESSION.CLOSE_DATABASE_LINK(‘AZURE_12CR2_PLUG.CLOUDAPP.NET’);
PL/SQL procedure successfully completed.
SQL>
SQL>