在mysql中,通过存储过程对日期进行计算的例子。
代码如下:
mysql> mysql> delimiter $$ mysql> mysql> CREATE PROCEDURE myProc() //创建存储过程 日期计算 -> BEGIN -> -> DECLARE TwentyYearsAgoToday DATE; -> DECLARE mystring VARCHAR(250); -> -> SET TwentyYearsAgoToday=DATE_SUB(curdate(), interval 20 year); -> -> SET mystring=CONCAT('It was ',TwentyYearsAgoToday,' ...'); -> -> SELECT mystring; -> -> END$$ Query OK, 0 rows affected (0.00 sec) mysql> delimiter ; mysql> mysql> call myProc(); //调用存储过程 +-----------------------+ | mystring | +-----------------------+ | It was 1987-07-23 ... | +-----------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.02 sec) mysql> drop procedure myProc; //删除存储过程 Query OK, 0 rows affected (0.00 sec)