create or replace procedure prc_test123 is
temp_columns varchar2(4000);
sqltemp varchar(20000);
cursor cur is select table_name from user_tables a where a.table_name like 'ZY%';
c_row cur%rowtype;
cursor t_cur(tablename varchar2) is select column_name from user_tab_columns a where a.table_name=tablename order BY column_name;
--type table_cur_type is ref cursor;
primaryLKey varchar2(20);
begin
for c_row in cur loop
temp_columns:='';
for t_c_row in t_cur(c_row.table_name) loop
if temp_columns is null or temp_columns='' then
dbms_output.put_line(temp_columns);
temp_columns:=t_c_row.column_name;
else
temp_columns:=temp_columns||','||t_c_row.column_name;
end if;
end loop;
--取出主键
select column_name into primaryLKey from user_cons_columns cu,
user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'P' and au.table_name =c_row.table_name;
--插入没有的主键数据
sqltemp:='insert into '||c_row.table_name ||' a ('||temp_columns||') SELECT '||temp_columns||' from data_manage.'||c_row.table_name ||' b where not exists(select 1 from '||c_row.table_name ||' c where c.'||primaryLKey||'=b.'||primaryLKey||')';
execute immediate sqltemp;
--更新已有的主键数据
sqltemp:='update '||c_row.table_name ||' a set ('||temp_columns||') = (SELECT '||temp_columns||' from data_manage.'||c_row.table_name ||' b where b.'||primaryLKey||'=a.'||primaryLKey||') where exists(select 1 from data_manage.'||c_row.table_name||' y where a.'||primaryLKey||'=y.'||primaryLKey||')';
execute immediate sqltemp;
end loop;
end;

  对于不同用户下同一张表的数据进行复制,已有数据进行更新,没有的数据进行插入

最新文章

  1. 快速掌握iOS API的一个小技巧
  2. 常用备份工具是mysql自带的mysqldump
  3. uva 10817(状压dp)
  4. java 字符串类型String
  5. 在Sharepoint2010中一种自定义调查列表的不允许再次答复提示的处理方法!
  6. PHP和ajax详解
  7. acdream 1412 2-3Trees (组合+DP)
  8. 《Windows核心编程》第5版 学习进度备忘
  9. 源代码解读Cas实现单点登出(single sign out)功能实现原理--转
  10. Windows调试工具入门—1
  11. HDU 3954 Level up(线段树)
  12. NYoj 素数环(深搜入门)
  13. Hacker Rank: Kingdom Division 不完全报告
  14. SSH 配置
  15. 【Codeforces 851D Arpa and a list of numbers】
  16. 【CF715E】Complete the Permutations 第一类斯特林数
  17. H5_ 多媒体video,autio使用示例
  18. C#.GetHashCode方法简单比较
  19. java中的线程问题是(四)——线程同步问题
  20. Reported time is too far out of sync with master. Time difference of 52692ms > max allowed of 30000ms

热门文章

  1. 数据结构(3) 第三天 栈的应用:就近匹配/中缀表达式转后缀表达式 、树/二叉树的概念、二叉树的递归与非递归遍历(DLR LDR LRD)、递归求叶子节点数目/二叉树高度/二叉树拷贝和释放
  2. flex笔记 - 基础
  3. [luogu3203 HNOI2010] 弹飞绵羊 (分块)
  4. python简单post信息
  5. hdu 4079简单贪心
  6. Linux常用命令last的使用方法详解
  7. C#高级编程八十三天----程序集的含义
  8. Linux 程序设计学习笔记----Linux下文件类型和属性管理
  9. 常用的Linux 命令
  10. 使用GitHub来托管Larval框架