oracle日期序列? [英] oracle date sequence?

查看:123
本文介绍了oracle日期序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个oracle数据库,我需要一个包含2年以上所有日期的表;
,例如从 01/01/2011 01/01/2013



首先我想到一个序列,但显然唯一支持的类型是数字,所以现在我正在寻找一种有效的方法来实现



cheers hoax

解决方案

如果你想要的是填充一连串日期的记录块,这很容易做。以下查询生成十个日期。所有您需要做的是调整种子日期,以便您通过子句在连接中为您提供起点和级别符合您的终点,然后将其插入插入语句。

  SQL>选择(trunc(sysdate,'MM') -  1)+级
2从双
3连接级别< = 10
4 /

(TRUNC (SY
---------
01-JAN-10
02-JAN-10
03-JAN-10
04-JAN- 10
05-JAN-10
06-JAN-10
07-JAN-10
08-JAN-10
09-JAN-10
10-JAN-10

选择10行

SQL>


I have an oracle db and I need a table containing all the dates spanning 2 years; for example from 01/01/2011 to 01/01/2013.

First I thought of a sequence but apparently the only supported type is number, so now I am looking for an efficient way to do this

cheers hoax

解决方案

If what you want is to populate a block of records with sequential dates, that is easy enough to do. The following query generates ten dates. All you need to do is adjust the seed date to give you your starting point and the level in the connect by clause to fit your end point, and then plug it into an insert statement.

SQL> select (trunc(sysdate, 'MM')-1) + level
  2  from dual
  3  connect by level <= 10
  4  /

(TRUNC(SY
---------
01-JAN-10
02-JAN-10
03-JAN-10
04-JAN-10
05-JAN-10
06-JAN-10
07-JAN-10
08-JAN-10
09-JAN-10
10-JAN-10

10 rows selected.

SQL>

这篇关于oracle日期序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆