zoukankan      html  css  js  c++  java
  • 记一次异地数据库表同步

    create or replace procedure syntest Authid Current_User is
    is_exit number;
    code_count number;
    code varchar2(10);
    begin
      --1.判断是否存在中间临时表b,不存在则根据源表a创建中间表b,并把全部数据同步到目标表kms_dot
         execute immediate 'select count(*) as is_exit from user_tables where table_name = ''T_ALL_AREA''' into is_exit;
         --dbms_output.put_line(is_exit);
         if  (is_exit = 0) then
           execute immediate 'create table t_all_area as select * from t_all_area@cssp';
           for i in (select * from t_all_area) loop
             code := i.id;
             select count(*) into code_count from kms_dot where locationcode = code;
             if (code_count = 0) then
               insert into kms_dot_syntest(LOCATIONCODE,LOCATIONNAME,STATUS,OPERUSER,OPRTDATETIME,OPERTIME)
               values(i.id,i.name,'1','万达数据库录入',sysdate,sysdate);
             end if;
           end loop;
         --2.关联源表a和中间临时表b,查出要插入的数据并插入到目标表kms_dot中
         else
           for i in (select a.* from t_all_area@cssp a left join t_all_area b on a.id = b.id where b.id is null) loop
             code := i.id;
             select count(*) into code_count from kms_dot where locationcode = code;
             if (code_count = 0) then
               insert into kms_dot_syntest(LOCATIONCODE,LOCATIONNAME,STATUS,OPERUSER,OPRTDATETIME,OPERTIME)
               values(i.id,i.name,'1','万达数据库录入',sysdate,sysdate);
             end if;
           end loop;
         end if;
         COMMIT;
    end syntest;

  • 相关阅读:
    P1440 求m区间内的最小值
    P1569 Generic Cow Protests
    P3252 [JLOI2012]树
    P3009 [USACO11JAN]Profits S
    <二分查找+双指针+前缀和>解决子数组和排序后的区间和
    常见算法技巧之——双指针思想
    设计模式——单例模式
    操作系统实验——读者写者模型(写优先)
    操作系统——内存管理学习笔记
    Altium Designer 16下载与安装教程
  • 原文地址:https://www.cnblogs.com/zsqfightyourway/p/10937733.html
Copyright © 2011-2022 走看看