database link远程链接数据库

--授权创建、删除dblink
GRANT CREATE [PUBLIC] DATABASE LINK,DROP [PUBLIC] DATABASE LINK TO canco;

--查看数据库GLOBAL_NAME(数据库名)
SELECT * FROM GLOBAL_NAME;    
    
--查看有哪些dblink
select owner,object_name from dba_objects where object_type='DATABASE LINK';
    
--删除dblink
DROP [public] DATABASE LINK nbcb;    
    
--==================================================================================================================
--创建dblink create database link local218 connect to CANCO identified by "123" using '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.218)(PORT = 1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=nbcb)))'; --创建同义词(隐藏链接的数据库) create synonym nbcb_fa_monthout_t for nbcb_fa_monthout_t@local218; --================================================================================================================== --truncate 语句无法执行 --1、在目标数据库中创建过程 create or replace procedure Remote_ExecuteDDL(sqltext in varchar2) authid current_user as begin execute immediate sqltext; end Remote_ExecuteDDL; --2、传递需要执行的sql Remote_ExecuteDDL@local218('truncate table canco.nbcb_fa_monthout_t'); --==================================================================================================================

 

--关闭database link连接的两种方式
1alter session close database link local218; 2、dbms_session.close_database_link('local218'); --====================================================================================================

 

总之,在使用DBLINK时一定要注意session的回收,在应用程序中使用

commit;

alter session close database link <dalink_name>;

 

execute immediate 'alter session close database link local218';

 

转载于:https://www.cnblogs.com/gavenQin/p/5650945.html

你可能感兴趣的:(database link远程链接数据库)