zoukankan      html  css  js  c++  java
  • db2 函数、存储过程示例

    1、函数

    --drop function getMaxDate; 
    create FUNCTION getMaxDate (y int, m int )
    returns date
    begin
         DECLARE maxDate date ;
         select max(dateid ) into maxDate from d_time where years = y and months = m;
         return maxDate;
    end;
    
    values getMaxDate(2013 ,3);

    2、存储过程

    --drop procedure test ; 
    
    CREATE  PROCEDURE TEST 
    ( IN BEGINDATE DATE , 
      IN ENDDATE DATE , 
      OUT NUM int 
    ) 
    begin
      declare currDate date ; -- 
      declare cy int ; 
      declare cm int ; 
      
      DECLARE  at_end    INT  DEFAULT  0 ; -- 
      DECLARE  not_found    CONDITION  FOR  SQLSTATE  '02000' ; -- 
      
    
      declare C1 cursor for
        select dateid , years ,months from d_time where dateid >beginDate and dateid <=endDate + 1  days order by dateid ; -- 
      DECLARE  CONTINUE  HANDLER  FOR  not_found    
        SET  at_end    =  1 ; -- 
          set num = 0 ; 
            open C1 ; -- 
            fetch  C1 into currDate ,cy ,cm ; -- 
                        
            WHILE  at_end = 0   DO 
    
              SET at_end =0 ; -- 
              fetch  C1 into currDate ,cy ,cm ; -- 
    
    
                  insert into test (dateid ,y , m ) values ( currDate ,cy ,cm ); 
       
                  set num = num + 1 ;
    
    
            END  WHILE ;   -- 
          CLOSE  C1 ;   -- 
    END ; 
    
    call test (date '2014-01-01' ,date '2014-02-23' , ?);
  • 相关阅读:
    原生js面试题
    ZJOI2017day2退役战
    uoj6
    uoj5
    uoj2
    uoj1
    论逗逼的自我修养之ZJOI2017Day1
    noip2016滚粗记
    统计损失
    珍珠项链
  • 原文地址:https://www.cnblogs.com/BlueBreeze/p/4242306.html
Copyright © 2011-2022 走看看