oracle sql查询列出上个月的所有日期

前端之家收集整理的这篇文章主要介绍了oracle sql查询列出上个月的所有日期前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
伙计们我要求列出上个月的所有日期,如下所示
20101201
20101202
20101203
20101204
20101205
..
..
..
..
..
..
..
..
20101231

如果有任何比这个查询更好的方法,请告诉我.

select TO_CHAR(TRUNC(SYSDATE,'MM')-1,'YYYYMMDD')-(level-1) as 
EACH_DATE from dual A connect by level 
< (TO_NUMBER(TO_CHAR(TRUNC(SYSDATE,'DD'))+1)

另请告诉我这个查询的问题,它说“缺少右括号”

SELECT /*+ PARALLEL (A,8) */ /*+ DRIVING_STATE */
   TO_CHAR(TRUNC(TRUNC(SYSDATE,'MM'),'MONYYYY') "MONTH",TYPE AS "TRAFF",COLUMN,A_COUN AS "A_COUNT",COST  FROM DATA_P B WHERE  EXISTS  
(  
  select TO_NUMBER(TO_CHAR(TRUNC(SYSDATE,'YYYYMMDD')-(level-1))  EACH_DATE 
  from dual A connect by  level < TO_NUMBER(TO_CHAR(TRUNC(SYSDATE,'DD')+1) 
  WHERE A.EACH_DATE = B.DATE  order by EACH_DATE ASC
 )

强调文字

听起来你想要这样的东西
sql> ed
Wrote file afiedt.buf

  1  select to_char( add_months(trunc(sysdate,-1) + level - 1,2                  'YYYYMMDD' )
  3    from dual
  4  connect by level <=
  5    last_day(add_months(trunc(sysdate,-1)) -
  6    add_months(trunc(sysdate,-1) +
  7*   1
sql> /

TO_CHAR(
--------
20101201
20101202
20101203
20101204
20101205
20101206
20101207
20101208
20101209
20101210
20101211
20101212
20101213
20101214
20101215
20101216
20101217
20101218
20101219
20101220
20101221
20101222
20101223
20101224
20101225
20101226
20101227
20101228
20101229
20101230
20101231

31 rows selected.
原文链接:https://www.f2er.com/oracle/205609.html

猜你在找的Oracle相关文章