1,mysql日期变量的实例代码。
mysql> mysql> delimiter $$ mysql> mysql> CREATE PROCEDURE myProc() //创建日期存储过程 -> BEGIN -> DECLARE my_dob DATE -> DEFAULT '1982-06-21'; /* My Birthday */ -> -> select my_dob; -> END$$ Query OK, 0 rows affected (0.00 sec) mysql> delimiter ; mysql> mysql> call myProc(); +------------+ | my_dob | +------------+ | 1960-06-21 | +------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql> mysql> drop procedure myProc; Query OK, 0 rows affected (0.02 sec)
2,创建默认日期 DATE DEFAULT '2008-12-31'
mysql> delimiter $$ mysql> mysql> CREATE PROCEDURE myProc() //存储过程 指定默认日期 -> BEGIN -> DECLARE l_date DATE DEFAULT '2008-12-31'; -> -> select l_date; -> END$$ Query OK, 0 rows affected (0.00 sec) mysql> delimiter ; mysql> mysql> call myProc(); //调用存储过程 +------------+ | l_date | +------------+ | 2008-12-31 | +------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql> mysql> drop procedure myProc; //删除存储过程 Query OK, 0 rows affected (0.00 sec)