<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    heting

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      40 隨筆 :: 9 文章 :: 45 評論 :: 0 Trackbacks
    drop procedure if exists pro_rep_shadow_rs;   
    delimiter 
    |   
    ----------------------------------   
    --
     rep_shadow_rs   
    --
     用來處理信息的增加,更新和刪除   
    --
     每次只更新上次以來沒有做過的數(shù)據(jù)   
    --
     根據(jù)不同的標(biāo)志位   
    --
     需要一個輸出的參數(shù),   
    --
     如果返回為0,則調(diào)用失敗,事務(wù)回滾   
    --
     如果返回為1,調(diào)用成功,事務(wù)提交   
    --
       
    --
     測試方法   
    --
     call pro_rep_shadow_rs(@rtn);   
    --
     select @rtn;   
    --
    --------------------------------   
    create procedure pro_rep_shadow_rs(out rtn int)   
    begin   
        
    -- 聲明變量,所有的聲明必須在非聲明的語句前面   
        declare iLast_rep_sync_id int default -1;   
        
    declare iMax_rep_sync_id int default -1;   
        
    -- 如果出現(xiàn)異常,或自動處理并rollback,但不再通知調(diào)用方了   
        -- 如果希望應(yīng)用獲得異常,需要將下面這一句,以及啟動事務(wù)和提交事務(wù)的語句全部去掉   
        declare exit handler for sqlexception rollback;   
        
    -- 查找上一次的   
        select eid into iLast_rep_sync_id from rep_de_proc_log where tbl='rep_shadow_rs';   
        
    -- 如果不存在,則增加一行   
        if iLast_rep_sync_id=-1 then   
          
    insert into rep_de_proc_log(rid,eid,tbl) values(0,0,'rep_shadow_rs');   
          
    set iLast_rep_sync_id = 0;   
        
    end if;   
           
        
    -- 下一個數(shù)字   
        set iLast_rep_sync_id=iLast_rep_sync_id+1;   
        
    -- 設(shè)置默認(rèn)的返回值為0:失敗   
        set rtn=0;   
           
        
    -- 啟動事務(wù)   
        start transaction;   
        
    -- 查找最大編號   
        select max(rep_sync_id) into iMax_rep_sync_id from rep_shadow_rs;   
        
    -- 有新數(shù)據(jù)   
        if iMax_rep_sync_id>=iLast_rep_sync_id then   
            
    -- 調(diào)用   
            call pro_rep_shadow_rs_do(iLast_rep_sync_id,iMax_rep_sync_id);   
            
    -- 更新日志   
            update rep_de_proc_log set rid=iLast_rep_sync_id,eid=iMax_rep_sync_id where tbl='rep_shadow_rs';   
        
    end if;   
           
        
    -- 運行沒有異常,提交事務(wù)   
        commit;   
        
    -- 設(shè)置返回值為1  
        set rtn=1;   
    end;   
    |   
    delimiter ;   
    drop procedure if exists pro_rep_shadow_rs_do;   
    delimiter 
    |   
    ---------------------------------   
    --
     處理指定編號范圍內(nèi)的數(shù)據(jù)   
    --
     需要輸入2個參數(shù)   
    --
     last_rep_sync_id 是編號的最小值   
    --
     max_rep_sync_id 是編號的最大值   
    --
     無返回值   
    --
    -------------------------------   
    create procedure pro_rep_shadow_rs_do(last_rep_sync_id int, max_rep_sync_id int)   
    begin   
        
    declare iRep_operationtype varchar(1);   
        
    declare iRep_status varchar(1);   
        
    declare iRep_Sync_id int;   
        
    declare iId int;   
        
    -- 這個用于處理游標(biāo)到達(dá)最后一行的情況   
        declare stop int default 0;   
        
    -- 聲明游標(biāo)   
        declare cur cursor for select id,Rep_operationtype,iRep_status,rep_sync_id from rep_shadow_rs where rep_sync_id between last_rep_sync_id and max_rep_sync_id;   
        
    -- 聲明游標(biāo)的異常處理,設(shè)置一個終止標(biāo)記   
        declare CONTINUE HANDLER FOR SQLSTATE '02000' SET stop=1;   
           
        
    -- 打開游標(biāo)   
        open cur;   
           
        
    -- 讀取一行數(shù)據(jù)到變量   
        fetch cur into iId,iRep_operationtype,iRep_status,iRep_Sync_id;   
        
    -- 這個就是判斷是否游標(biāo)已經(jīng)到達(dá)了最后   
        while stop <> 1 do  
            
    -- 各種判斷   
            if iRep_operationtype='I' then   
                
    insert into rs0811 (id,fnbm) select id,fnbm from rep_shadow_rs where rep_sync_id=iRep_sync_id;   
            elseif iRep_operationtype
    ='U' then   
            
    begin   
                
    if iRep_status='A' then   
                    
    insert into rs0811 (id,fnbm) select id,fnbm from rep_shadow_rs where rep_sync_id=iRep_sync_id;   
                elseif iRep_status
    ='B' then   
                    
    delete from rs0811 where id=iId;   
                
    end if;   
            
    end;   
            elseif iRep_operationtype
    ='D' then   
                
    delete from rs0811 where id=iId;   
            
    end if;    
               
            
    -- 讀取下一行的數(shù)據(jù)    
            fetch cur into iId,iRep_operationtype,iRep_status,iRep_Sync_id;   
        
    end while;  -- 循環(huán)結(jié)束   
        close cur; -- 關(guān)閉游標(biāo)   
     end;   
    posted on 2009-03-25 09:55 賀挺 閱讀(532) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲国产成人综合精品| 精品免费久久久久久成人影院| 666精品国产精品亚洲| AA免费观看的1000部电影| 色偷偷亚洲男人天堂| 日韩精品无码区免费专区| 老色鬼久久亚洲AV综合| 免费A级毛片无码免费视| 国产免费一区二区三区免费视频 | 欧洲美女大片免费播放器视频| 日本亚洲视频在线| 成人最新午夜免费视频| 久久久久久国产a免费观看不卡| 亚洲电影在线播放| 亚洲视频在线精品| 在线观看的免费网站| 日批视频网址免费观看| 亚洲国产AV无码一区二区三区 | 亚洲欧美日韩久久精品| 欧美a级在线现免费观看| ssswww日本免费网站片| 亚洲jjzzjjzz在线播放| 区久久AAA片69亚洲| 久久青草精品38国产免费| 久久精品国产亚洲精品2020| 免费国产a国产片高清网站| 黄页网站在线免费观看| 亚洲综合无码一区二区三区| 亚洲色一色噜一噜噜噜| 成人免费午夜视频| 91av在线免费视频| 亚洲熟妇无码AV不卡在线播放| 亚洲人成图片小说网站| 四虎永久在线精品免费影视| 青娱分类视频精品免费2| 精品国产亚洲第一区二区三区 | 国产亚洲精品91| 国产91在线|亚洲| 亚洲综合无码一区二区| 国产亚洲精品成人AA片新蒲金 | 永久免费无码日韩视频|