« 江湖传闻:猫扑将与华友世纪合并 | Blog首页 | DB link与检查点(checkpoint)和SCN »
如何通过DB link进行远程过程或函数调用
链接:https://www.eygle.com/archives/2006/11/db_link_remote_function.html
有朋友在留言板问:如何通过动态sql远程调用包里面的函数,并返回值。
我简单做了一个例子,实现以上要求.
首先进行适当授权:
[oracle@jumper oracle]$ sqlplus "/ as sysdba"SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 7 21:07:56 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - ProductionSQL> grant create public database link to eygle;
Grant succeeded.
SQL> grant all on dbms_flashback to eygle;Grant succeeded.
建立DB Link:
SQL> connect eygle/eygle
Connected.
SQL> create public database link hsbill using 'hsbill';Database link created.
SQL> select db_link from dba_db_links;
DB_LINK
---------------------------------------------------
HSBILLSQL> select * from dual@hsbill;
D
-
X
此后可以尝试使用DB Link进行远程和本地执行:
SQL> set serveroutput on
SQL> set feedback off
SQL> declare
2 r_gname varchar2(40);
3 l_gname varchar2(40);
4 begin
5 execute immediate
6 'select GLOBAL_NAME from global_name@hsbill' into r_gname;
7 dbms_output.put_line('gname of remote:'||r_gname);
8 select GLOBAL_NAME into l_gname from global_name;
9 dbms_output.put_line('gname of locald:'||l_gname);
10 end;
11 /
gname of remote:HSBILL.HURRAY.COM.CN
gname of locald:EYGLE
远程Package或Function调用也可以随之实现:
SQL> declare
2 r_scn number;
3 l_scn number;
4 begin
5 execute immediate
6 'select dbms_flashback.GET_SYSTEM_CHANGE_NUMBER@hsbill from dual' into r_scn;
7 dbms_output.put_line('scn of remote:'||r_scn);
8 end;
9 /
scn of remote:18992092687
SQL>
-The End-
历史上的今天...
>> 2017-11-07文章:
>> 2011-11-07文章:
>> 2008-11-07文章:
>> 2007-11-07文章:
>> 2005-11-07文章:
By eygle on 2006-11-07 21:36 | Comments (12) | HowTo | 959 |
使用含有远程函数的select语句,将数据insert到本地数据库中,也能实现么?要不要授权什么的?
能够查询到远程数据,自然很容易insert到本地啊。
如果在本地执行远程调用,本地的相应权限应该是已经具备了的。
insert into aa
select * from reo@dblink where .....;
这个语句是可以执行的
但是如果
insert into aa
select * from re@dblink where getxie(...)
上面getxie()是一个远程函数,则提示出错
在where条件里这样写是不行的,这样写会执行本地调用了,你可以把功能整体封装到远程过程中。
远程过程,还没有学习过,找资料来看看
db_domain中的名字中含有_的不能这么处理吧
"-"或者"_"都可能存在问题。
以前遇到过高级复制"-"存在问题的情况:
http://www.eygle.com/archives/2005/06/ssoeiieeoioeoeo.html
至于在这里测试一下就知道了。
从v$database和从dbms_flashback.get_system_change_num中查询出来的当前SCN总有差异,是否是因为在我切换查询语句的这个时间点中SCN就已经发生变化了?但是记得你在书上说SCN是3秒才变一次,但是这两个地方查询出来的SCN相差8-20.
不好意思,发错地方了,应该是另外一个贴子下
没有参数的过程,或者函数可以如上面那样写。如果有参数需要把参数放在dblink名字的后面。
insert into aa
select * from re@dblink where getxie@dblink(...)
select * from re@dblink where getxie@dblink(...)
这句确实很好用 谢谢
又是把你的文章据为己有的人,BS这种人
http://www.hkdg.net/html/xx/SQL/Oracle/2009/0328/21089.html