DB2 functions, stored procedure Examples

Source: Internet
Author: User
Tags db2 db2 functions

1. Functions

--drop function getmaxdate;Create FUNCTIONGetmaxdate (yintMint )returnsDatebegin     DECLAREmaxdate date; Select Max(DateID) intoMaxDate fromD_timewhereYears=Y andMonths=m; returnmaxdate;End;Values Getmaxdate (2013, 3);

2. Stored Procedures

--drop procedure test;CREATE  PROCEDURETEST (inchbegindate DATE,inchENDDATE DATE, out NUMint ) begin  DeclareCurrdate date;--   DeclareCyint ; DeclareCmint ; DECLAREAt_endINT  DEFAULT  0;--   DECLARENot_found CONDITION forSQLSTATE'02000';--     DeclareC1cursor  for    SelectDateID, years, months fromD_timewhereDateID>Begindate andDateID<=EndDate+ 1DaysOrder  byDateID;--   DECLARE  CONTINUEHANDLER forNot_foundSETAt_end=  1;--       SetNum= 0 ; OpenC1;--         FetchC1 intoCurrdate, CY, CM;--                              whileAt_end= 0 DoSETAt_end=0;--           FetchC1 intoCurrdate, CY, CM;--               Insert  intoTest (DateID, Y, M)Values(currdate, CY, CM); SetNum=Num+ 1 ; END   while;--       CLOSEC1;-- END; Call Test (date'2014-01-01', date'2014-02-23', ?);

DB2 functions, stored procedure Examples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.