免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1348 | 回复: 0
打印 上一主题 下一主题

请教一个与时间有关的存储过程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-12-26 14:55 |只看该作者 |倒序浏览
想往TABLE中插入下列数据
2006-1-1                      0   2006 200601 20060101
2006-1-1 1:00:00         1   2006 200601 20060101
2006-1-1 2:00:00         2   2006 200601 20060101
.....
2006-12-31 23:00:00  23   2006 200612 20061231
注:每天的第一条数据(零点) 没有0:00:00
即 插入的是:2006-1-1 而不是 2006-1-1 0:00:00
我写的:
CREATE PROCEDURE  SP_TEST2()
define  iCount int;
let iCount=1;
while (iCount<=8736)
    insert into stat_lookup_day(hour_id,hour_desc,year_id,month_id,day_id)
    values
    ( to_char(to_date('2006-01-01','yyyy-mm-dd hh:MM:ss')+iCount,'yyyy-mm-dd hh:MM:ss'),
      to_char(to_date('2006-01-01','yyyy-mm-dd hh:MM:ss')+iCount,'HH'),
      to_char(to_date('2006-01-01','yyyy-mm-dd hh:MM:ss')+iCount,'yyyy'),
      to_char(to_date('2006-01-01','yyyy-mm-dd hh:MM:ss')+iCount,'yyyymm'),
      to_char(to_date('2006-01-01','yyyy-mm-dd hh:MM:ss')+iCount,'yyyymmdd')
        );
   let iCount=iCount+1;
end while;
END PROCEDURE
有错误,请大家指正
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP