示例:
date_add()函数:
DELIMITER |
create dba function gbasedbt.date_add(date_exp date, interval_int int, int_type varchar(25))
returns date;
define r_date date;
if upper(int_type)='YEAR' then
select (date_exp+interval_int units YEAR) into r_date from systables where tabid=1;
elif upper(int_type)='QUARTER' then
select (date_exp+interval_int*3 units MONTH) into r_date from systables where tabid=1;
elif upper(int_type)='MONTH' then
select (date_exp+interval_int units MONTH) into r_date from systables where tabid=1;
elif upper(int_type)='WEEK' then
select (date_exp+interval_int*7 units DAY) into r_date from systables where tabid=1;
elif upper(int_type)='DAY' then
select (date_exp+interval_int units DAY) into r_date from systables where tabid=1;
else
select int_type into r_date from systables where tabid=1;
end if;
return r_date;
end function;

本文介绍了一个自定义的date_add()函数,用于日期的加减运算,包括年、月、日、季度和星期;以及datetime_add()函数,用于时间的加减运算,包括小时、分钟和秒。提供了使用示例。
最低0.47元/天 解锁文章
1349





