在mysql中有一个函数叫extract,用于时间的处理实在是太有用了,比如要从日期中提取出年月,这样写就可以了:
- select extract(YEAR_MONTH from begin_date) into begin_month;
该函数的原型是:
- extract (unit from date)
其中unit支持的类型有:
MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR,
DAY_MICROSECOND, HOUR_MICROSECOND, MINUTE_MICROSECOND, SECOND_MICROSECOND,
DAY_HOUR,
DAY_MINUTE, HOUR_MINUTE,
DAY_SECOND, HOUR_SECOND, MINUTE_SECOND,
YEAR_MONTH
转载于:https://blog.51cto.com/ustb80/1030604