你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle数据比对(DBMS_COMPARISON)

[日期:2014-10-10] 来源:Linux社区  作者:rhys_oracle [字体:大 中 小]

第二步创建比对任务:

对了忘记提一下权限了,对于该包,要有如下权限:

SQL> grant execute on dbms_comparison to scott;

Grant succeeded.

SQL> grant execute_catalog_role to scott;

Grant succeeded.

SQL>

 

SQL>  begin
  2  dbms_comparison.create_comparison(
  3  comparison_name=>'test1',
  4  schema_name=>'SCOTT',
  5  object_name=>'DEPT',
  6  dblink_name=>'comparison_link'
  7  );
  8  end;
  9  /

PL/SQL procedure successfully completed.

SQL>

好这样就做完第一步了。

当源端和目标端数据对象的列不一致的情况会出现如下错误:

 SQL>  begin
  2  dbms_comparison.create_comparison(
  3  comparison_name=>'test1',
  4  schema_name=>'SCOTT',
  5  object_name=>'EMP',
  6  dblink_name=>'comparison_link'
  7  );
  8  end;
  9  /
 begin
*
ERROR at line 1:
ORA-23625: Table shapes of SCOTT.EMP and SCOTT.EMP@COMPARISON_LINK did not match.
ORA-06512: at "SYS.DBMS_COMPARISON", line 5008
ORA-06512: at "SYS.DBMS_COMPARISON", line 448
ORA-06512: at line 2

那么怎么办呢?和我说的是做一个column_list;

第二步开始进行数据比对:

SQL> declare
  2  compare_info dbms_comparison.comparison_type;
  3  compare_return boolean;
  4  begin
  5  compare_return := dbms_comparison.compare (comparison_name=>'test1',
  6  scan_info=>compare_info,
  7  perform_row_dif=>TRUE);
  8 
  9  if compare_return=TRUE
 10  then
 11  dbms_output.put_line('the tables are equivalent.');
 12  else
 13  dbms_output.put_line('Bad news... there is data divergence.');
 14  dbms_output.put_line('Check the dba_comparison and dba_comparison_scan_summary views for locate the differences for scan_id:'||compare_info.scan_id);
 15  end if;
 16  end;
 17  /
the tables are equivalent.

PL/SQL procedure successfully completed.

SQL>

第三步查看比对结果:

SQL> select * from user_comparison_scan
  2  ;

COMPARISON_NAME        SCAN_ID PARENT_SCAN_ID ROOT_SCAN_ID STATUS          CURRENT_DIF_COUNT INITIAL_DIF_COUNT COUNT_ROWS S LAST_UPDATE_TIME
-------------------- ---------- -------------- ------------ ---------------- ----------------- ----------------- ---------- - ----------------------------------------
TEST1                        1                          1 SUC                              0                0          4 N 19-AUG-14 11.05.42.780593 PM
TEST1                        2                          2 SUC                              0                0          4 N 19-AUG-14 11.11.37.613343 PM

SQL> select * from user_comparison_row_dif;

no rows selected

SQL>

好了,简简单单就到这了。

当然如果敢兴趣可以自己在测试其他的。

我要把数据清掉了:

SQL> begin
  2  dbms_comparison.purge_comparison(
  3  comparison_name=>'test1');
  4  end;
  5  /

PL/SQL procedure successfully completed.

SQL> select * from user_comparison_scan;

no rows selected

SQL>

that's all!

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-10/107849.htm

linux
相关资讯       Oracle数据比对 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款