lei's profile我就是我PhotosBlogListsMore Tools Help
    August 30

    垃圾的DB2

    最近在用DB2 实实证明不开放的东西就是不好用。妈妈的
    下面一个例子,留作以后当资料了
     

    CREATE PROCEDURE P_MK_FactoryHours_login()
    --营销_火电企业发电设备利用小时(月度)—数据初始化
         LANGUAGE SQL    
       p1:BEGIN
         DECLARE   SQLSTATE   CHAR(5);  
         DECLARE NOW_DATE VARCHAR(10);--当前日期
         DECLARE PLANT_ID VARCHAR(20);
         DECLARE PLANT_FMonthComplete DECIMAL(20,5);
         DECLARE PLANT_FYearComplete DECIMAL(20,5);
         DECLARE   sqlcode   INT   DEFAULT   0;
            
        
    --"02000"就表示游标位置已经处于结果表最后一行之后    
         --DECLARE   not_found   CONDITION   FOR   SQLSTATE   '02000';
    --开启宗产数据本月的游标    
         DECLARE c1 CURSOR FOR
      select substr(char(id),1,length(char(id))-2), M_USER_HOURS, USE_HOURS
      from PLANT_BRIEF
      where substr(char(TAB_YEAR),1,length(char(TAB_YEAR))-2) = substr(NOW_DATE,1,4)
      and substr(char(TAB_MONTH),1,length(char(TAB_MONTH))-2) = substr(NOW_DATE,6,2);    
         --DECLARE CONTINUE HANDLER FOR NOT FOUND
          --SET   at_end   =   -1;
       --SET at_end = 0;
     --取系统日期
         select (current date) into NOW_DATE
         from (select count(*) from   plant_tree) as a  
         fetch first 1 rows only;        
        
         open c1;
         ins_loop:  
            LOOP  
                FETCH   c1   INTO   PLANT_ID,   PLANT_FMonthComplete,   PLANT_FYearComplete; 
        --判断游标结束        
                IF sqlcode=100  THEN         
                    LEAVE   ins_loop;
                END   IF;       
        --初始化数据      
                update T_MK_FactoryHours set FMonthComplete = PLANT_FMonthComplete ,FYearComplete = PLANT_FYearComplete
                where FDepNo = PLANT_ID and substr(FReportPeriod,1,7) = substr(NOW_DATE,1,7);
                   
            END LOOP ins_loop; 
      CLOSE   c1;   
       END  p1
    @
     

    Comments (2)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    兵 王wrote:
     看不懂啊??
    3 Sept.
    川 牟wrote:
     还在用存储过程?
    3 Sept.

    Trackbacks

    The trackback URL for this entry is:
    http://mousexian.spaces.live.com/blog/cns!15D473ECCE04126!699.trak
    Weblogs that reference this entry
    • None