获取当前月份的每一天的数据

oracle

SELECT TO_DATE(TO_CHAR(SYSDATE, 'YYYYMM'), 'YYYYMM') + (ROWNUM - 1) DAY_ID
  FROM DUAL
CONNECT BY ROWNUM <=
           TO_NUMBER(TO_CHAR(LAST_DAY(TO_DATE(TO_CHAR(SYSDATE, 'YYYYMM'),
                                              'YYYYMM')),
                             'DD'))

mysql

SELECT
  DATE_ADD(CURDATE(),INTERVAL(CAST(help_topic_id AS SIGNED INTEGER)-(DAYOFMONTH(CURDATE())-1)) DAY) DAY
FROM mysql.help_topic
WHERE help_topic_id < DAY(LAST_DAY(CURDATE()))
ORDER BY help_topic_id

备注:help_topic为mysql存储内置函数的表


标题:oracle和mysql遍历当前月份每一天
作者:upaths
地址:http://noyil.com/daily-sql