本人想在mysql的过程里,设置一个变量,得到的是上个月的第一天,但本人这里into不进去,不知道该 怎么解决,求高手们帮看下
— 上个月的第一天
DECLARE V_START_DAY DATETIME;
— 获取上个月的第一天
SELECT DATE_SUB(DATE_SUB(DATE_FORMAT(NOW(),”%Y-%M-%D”),
INTERVAL EXTRACT(DAY FROM NOW())-1 DAY),INTERVAL 1 MONTH) INTO V_START_DAY FROM DUAL;
解决方案
100
mysql> select curdate(); +--+ | curdate() | +--+ | 2016-07-16 | +--+ 1 row in set (0.01 sec) mysql> select curdate()-interval day(curdate())-1 day - interval 1 month ; +--+ | curdate()-interval day(curdate())-1 day - interval 1 month | +--+ | 2016-06-01 | +--+ 1 row in set (0.00 sec) mysql> select curdate()-interval day(curdate())-1 day - interval 1 month into @V_START_DAY ; Query OK, 1 row affected (0.00 sec) mysql> select @V_START_DAY; +--+ | @V_START_DAY | +--+ | 2016-06-01 | +--+ 1 row in set (0.00 sec) mysql> mysql>