比对两个数据库的表结构

select a.table_name user1_table,  a.column_name user1_column,          b.table_name , b.column_name user2_column     from (select table_name, column_name from dba_tab_columns           where owner= 'USER1' ) a,          (select table_name, column_name from dba_tab_columns           where owner= 'USER2' ) b     where a.table_name(+) = b.table_name       and a.column_name(+) = b.column_name       and a.column_name is null   union all   select a.table_name user1_table,  a.column_name user1_column,          b.table_name user2_table, b.column_name user2_column     from (select table_name, column_name from dba_tab_columns           where owner= 'USER1' ) a,          (select table_name, column_name from dba_tab_columns           where owner= 'USER2' ) b     where a.table_name = b.table_name(+)       and a.column_name = b.column_name(+)       and b.column_name is null;

select case when a.cnt = b.cnt then '两个库结构一致' when a.cnt <> b.cnt then '两个库结构不一致' end from (select count(*) as cnt from dba_tab_columns t1, dba_tab_columns@lnk_db2 t2 where t1.owner = 'TAOBAO' and t1.owner = t2.owner and t1.table_name = t2.table_name and t1.column_name = t2.column_name and t1.data_type = t2.data_type and t1.data_length = t2.data_length and t1.nullable = t2.nullable and nvl(t1.data_precision, 0) = nvl(t2.data_precision, 0) and nvl(t1.data_scale, 0) = nvl(t2.data_scale, 0)) a, (select count(*) as cnt from dba_tab_columns where owner = 'TAOBAO') b

posted @ 2013-12-05 16:21  bj_google  阅读(824)  评论(0编辑  收藏  举报