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 '' ; -- 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' , ?);

db2 函数、存储过程示例的更多相关文章

  1. DB2函数简单示例

    DB2中的函数原理同其他编程语言中的函数,均为输入几个参数,同时返回一个值. 下面的例子演示一个寻找某一次考试中成绩最好的学生的姓名. 首先,我们新建一个表SCORE用于表示考试,并插入几条数据: D ...

  2. DB2 函数大全

    DB2函数大全 函数名 函数解释 函数举例 AVG() 返回一组数值的平均值. SELECTAVG(SALARY)FROMBSEMPMS; CORR(),CORRELATION() 返回一对数值的关系 ...

  3. DB2函数大全

    DB2函数大全 函数名 函数解释 函数举例 AVG() 返回一组数值的平均值. SELECTAVG(SALARY)FROMBSEMPMS; CORR(),CORRELATION() 返回一对数值的关系 ...

  4. python 全栈开发,Day64(视图,触发器,函数,存储过程,事务)

    昨日内容回顾 pymysql:属于python的一个模块 pip3 install pymysql conn = pymysql.connect(...,charset = 'uft8') 创建游标 ...

  5. oracle常用函数及示例

    学习oracle也有一段时间了,发现oracle中的函数好多,对于做后台的程序猿来说,大把大把的时间还要学习很多其他的新东西,再把这些函数也都记住是不太现实的,所以总结了一下oracle中的一些常用函 ...

  6. mysqldump导出--数据+结构+(函数+存储过程)

    #导出某个数据库--结构+数据shell>mysqldump -h192.168.161.124 -uroot -pxxxxxx --opt db_name |gzip -9 > /db_ ...

  7. Shell脚本中使用function(函数)示例

    这篇文章主要介绍了Shell脚本中使用function(函数)示例,本文着重讲解的是如何在shell脚本中使用自定义函数,并给出了两个例子,需要的朋友可以参考下   函数可以在shell script ...

  8. JS的document.links函数使用示例

    ? <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title&g ...

  9. JS的document.images函数使用示例

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. JS的document.anchors函数使用示例

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

随机推荐

  1. hook Extending the Framework Core

    w Task Scheduling - Laravel - The PHP Framework For Web Artisanshttps://laravel.com/docs/5.4/schedul ...

  2. EIT: where is it now and what lies ahead?

    EIT: where is it now and what lies ahead? Electrical impedance tomography (EIT) is an emerging clini ...

  3. 【转】spring boot application.properties 配置参数详情

    multipart multipart.enabled 开启上传支持(默认:true) multipart.file-size-threshold: 大于该值的文件会被写到磁盘上 multipart. ...

  4. Rooks---LightOj1005(排列组合)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1005 题意就是在一个n*n的方格中放k个棋子,每一行每一列都不能有两个棋子,问有多少种 ...

  5. Spark2.0 协同过滤推荐

    ALS矩阵分解 http://blog.csdn.net/oucpowerman/article/details/49847979 http://www.open-open.com/lib/view/ ...

  6. 如何在mysql中存储音乐和图片文件

    如何在mysql中存储音乐和图片文件? 果你想把二进制的数据,比如说图片文件和HTML文件,直接保存在你的MySQL数据库,那么这篇文章就是为你而写的! 我将告诉你怎样通过HTML表单来储存这些文件, ...

  7. java并发 —— Lock

    java并发 -- Lock 关于java并发中的锁知识,少不了 Lock.本文转载自:Java并发编程:Lock. 从Java 5之后,在java.util.concurrent.locks包下提供 ...

  8. 写几个简单用artTemplate的例子

    写几个简单的artTemplate的例子,很多框架都有自己的模板(template),没得时候,可以利用artTemplate.js完成 html文件是: <!DOCTYPE html> ...

  9. 10 Linux Commands Every Developer Should Know

    转载:http://azer.bike/journal/10-linux-commands-every-developer-should-know/ As a software engineer, l ...

  10. Ubuntu16.04中用et对jmeter生成的数据统计成图表

    在Ubuntu系统中,用ctrl+Alt+t 打开终端: 输入et,即打开wps: 整理需要形成图表的数据,如: 用excel生成图表,如下: 表得出的性能图表,方法: 1.工具栏中选择插入——二维折 ...