Home   Oracle SQL Scripts   Contact link Contact:  jack@dughaille.info

Description:
Closes any database links open in the session. Have to issue a "commit" or "rollback" first.

Example output:
SQL> rollback; Rollback complete. SQL> @close_dbl Closing database link PETERM_DEV01 Closing database link PETERM_LIV02 Closing database link PETERM_SORT1 Closing database link PETERM_UAT01 PL/SQL procedure successfully completed.

Script:
prompt -- Closes open database links in the current session: need to execute rollback or commit before running prompt declare cursor c_open_links is select * from v$dblink; begin for i in c_open_links loop if '&1' <> 'SILENT' then dbms_output.put_line( 'Closing database link ' || i.db_link ); end if; execute immediate 'alter session close database link ' || i.db_link; end loop; end; /