eygle.com   eygle.com
eygle.com  
 

« 江湖传闻:猫扑将与华友世纪合并 | Blog首页 | DB link与检查点(checkpoint)和SCN »

如何通过DB link进行远程过程或函数调用

作者:eygle |【转载时请务必以超链接形式标明文章和作者信息及本声明
链接:

有朋友在留言板问:如何通过动态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 - Production

SQL> 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
---------------------------------------------------
HSBILL

SQL> 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-

By eygle on 2006-11-07 21:36 | Comments (10) | Posted to HowTo | Edit |Pageviews:

相关文章 随机文章
  • 使用分析函数进行行列转换
  • 如何对时间进行简单加减运算
  • 并行查询并行度Degree与instances 设置
  • 关于PARALLEL_MAX_SERVERS参数的设置
  • 使用REF CURSOR处理Oracle的结果集
  • Oracle HowTo: How to deal with Ora-600 4193 error
    Oracle Diagnostics:又见ORA-04031
    中国歌舞剧院 新年交响音乐会
    一则简单的磁盘的iops测试
    遭遇不明流量攻击 网络是危险的
    网上相关主题:
    Google

    留言 (10)

    使用含有远程函数的select语句,将数据insert到本地数据库中,也能实现么?要不要授权什么的?

    Posted by: fwpmsy at November 8, 2006 3:39 PM

    能够查询到远程数据,自然很容易insert到本地啊。

    如果在本地执行远程调用,本地的相应权限应该是已经具备了的。

    Posted by: eygle at November 9, 2006 8:37 AM

    insert into aa
    select * from reo@dblink where .....;
    这个语句是可以执行的
    但是如果
    insert into aa
    select * from re@dblink where getxie(...)
    上面getxie()是一个远程函数,则提示出错

    Posted by: fwpmsy at November 9, 2006 12:37 PM

    在where条件里这样写是不行的,这样写会执行本地调用了,你可以把功能整体封装到远程过程中。

    Posted by: eygle at November 9, 2006 2:48 PM

    远程过程,还没有学习过,找资料来看看

    Posted by: fwpmsy at November 9, 2006 3:49 PM

    db_domain中的名字中含有_的不能这么处理吧

    Posted by: 冰冻奶茶 at September 19, 2007 2:36 PM

    "-"或者"_"都可能存在问题。
    以前遇到过高级复制"-"存在问题的情况:
    http://www.eygle.com/archives/2005/06/ssoeiieeoioeoeo.html

    至于在这里测试一下就知道了。

    Posted by: eygle at September 19, 2007 3:43 PM

    从v$database和从dbms_flashback.get_system_change_num中查询出来的当前SCN总有差异,是否是因为在我切换查询语句的这个时间点中SCN就已经发生变化了?但是记得你在书上说SCN是3秒才变一次,但是这两个地方查询出来的SCN相差8-20.

    Posted by: 小花猫 at November 9, 2007 10:29 AM

    不好意思,发错地方了,应该是另外一个贴子下

    Posted by: 小花猫 at November 9, 2007 10:30 AM

    没有参数的过程,或者函数可以如上面那样写。如果有参数需要把参数放在dblink名字的后面。

    insert into aa
    select * from re@dblink where getxie@dblink(...)

    Posted by: sinclair at December 18, 2007 4:21 PM

    发表留言:



    Remember Me?
    (输入验证码后方可评论,谢谢支持)



    CopyRight © 2004 eygle.com, All rights reserved.