我单位有十一台服务器,用于存储下级十一个单位的数据库,数据库结构一致,现还没有实现数据集中,但目前在做的一个查询需要从指定的一个或多个服务器中查询数据,我试过用数据库链路,如:
原sql:
select a,b,c from aa where a='1';根据用户选择要查询的单位,动态生成如下sql语句(如选择a、b、f单位)
select a,b,c from aa@a where a='1'
union
select a,b,c from aa@b where a='1'
union
select a,b,c from aa@f where a='1'在执行时系统提示数据库链路过多
请问在无法实现数据集中之前,如何实现以上需求?

解决方案 »

  1.   

    数据库版本?9.2.0.4是没有问题的
    SQL> select 1 from dual@wlmqbill
      2  union all
      3  select 1 from dual@to_ks9
      4  union all
      5  select 1 from dual@t43
      6  ;         1
    ----------
             1
             1
             1
    要是数据库版本的问题导致上述错误的话,可以通过建一个临时表来处理。
    insert into temp_table select a,b,c from aa@a where a='1';
    insert into temp_table select a,b,c from aa@b where a='1';
    insert into temp_table select a,b,c from aa@c where a='1';
    commit;
    select a,b,c from temp_temp_table;