How to generate dates in one year?

helpall 2004-08-13 12:24:03
Hi,

In one of the queries, we get:

01/01/2003 10
01/03/2003 1
...

We want to show
01/01/2003 10
01/02/2003 0
01/03/2003 0
01/04/2003 1
...

Is there a way to generate all the dates, say, for one year?

Thanks.
...全文
147 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tyrone98 2004-08-13
  • 打赏
  • 举报
回复
你这种还是很麻烦的,有以下几种办法
1.建一个函数,返回一年中所有日的数组,然后使用
select a ,( select b from tab where dt = e.dt ) from table( ff() ) e ;
2.建一个表,表里放一年的数据.再取出来。
hevin 2004-08-13
  • 打赏
  • 举报
回复
sql 语句如何插入全年日期?
create table BSYEAR (d date);
insert into BSYEAR
select to_date('20030101','yyyymmdd')+rownum-1
from all_objects
where rownum <= to_char(to_date('20031231','yyyymmdd'),'ddd');
helpall 2004-08-13
  • 打赏
  • 举报
回复
dinya2003(OK):
谢谢。
能给个具体点的例子吗?
helpall 2004-08-13
  • 打赏
  • 举报
回复
我是用这个做的
select dd
from
(
select to_date('040101','YYMMDD')+rownum -1 dd
from <any_table_with_more_than_366_rows>
where rownum < 367
)
where to_char(dd,'YY') = '04'
;

各位高手,不知有无更好的方法.
helpall 2004-08-13
  • 打赏
  • 举报
回复
我是用这个做的
select dd
from
(
select to_date('040101','YYMMDD')+rownum -1 dd
from <any_table_with_more_than_366_rows>
where rownum < 367
)
where to_char(dd,'YY') = '04'
;

各位高手,不知有无更好的方法.
dinya2003 2004-08-13
  • 打赏
  • 举报
回复
从第一个日期开始,转换成字符,月份循环加一,再转换成日期,和表关联查询
helpall 2004-08-13
  • 打赏
  • 举报
回复
谢谢林林.

这个办法我知道. 看看有没有高手来.

17,140

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧