Oracle dblink远程调用存储过程、函数、序列

一、dblink远程调用procedure: 

1、写了一个调用远端sayHello存储过程的存储过程,远端sayHello存储过程如下:

 

-- 远端 sayHello 定义如下:
create or replace procedure sayHello(currentTime out varchar) is
begin
   select 'Hello World' into currentTime from dual;
end sayHello;

 

 2、实现的sayRemoteHello存储过程如下:

 

create or replace procedure sayRemoteHello(name varchar, pwd varchar, ip varchar) authid current_user as
sqlstr varchar(1000);
r varchar(100);
begin
  sqlstr:='drop database link tlink';
  execute immediate sqlstr;
--  sqlstr:= 'create database link tlink connect to scott identified by fj1234 using ''(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.70)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = orcl)))''';
--  SERVICE_NAME 使用 SELECT * FROM GLOBAL_NAME; 可查,默认为orcl
  sqlstr:= 'create database link tlink connect to '||name||' identified by '||pwd||' using ''(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = '||ip|| ')(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = orcl)))''';
  
  execute immediate sqlstr;
  sqlstr:='begin sayHello@tlink(:a); end;';
  execute immediate sqlStr using out r;
  
  dbms_output.put_line(r);
end sayRemoteHello;

 

3、 测试如下:

 

--测试:call sayRemoteHello('scott', 'fj1234', '192.168.0.70');

 

二、dblink远程调用function:

 

 

 

三、dblink远程调用sequence:

SELECT 序列名.NEXTVAL@方案名 FROM DUAL;
如:
SELECT S_USER.NEXTVAL@SKOCRM FROM DUAL;
   

 

 

 

 

 

你可能感兴趣的:(Oracle)