如何在 Oracle 中填充日历表? [英] How to populate calendar table in Oracle?

查看:33
本文介绍了如何在 Oracle 中填充日历表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Oracle DB 中维护一个日历表,我想用从 2011 年到 2013 年开始的一年中的所有日子(可能一直到任何一年)来填充它.我该怎么做?

I want to maintain a calender table in Oracle DB which I want to populate with all the days of the year starting from 2011 to 2013 (it may be till any year). How can I do that?

考虑我的数据库表有列,示例数据集是:

Consider my DB table has columns and example dataset is:

S.No  Cal_Dt      DayName 
1     01-01-2011  Monday
2     02-01-2011  Tuesday
3     03-01-2011  Wednesday

等等.

我只关心这里的 Cal_Dt(DayName 是可选的).

I am more concerned with the Cal_Dt only here (DayName is optional).

推荐答案

这是一个简单易行的方法

This is a simple and easy way to do it

with calendar as (
        select :startdate + rownum - 1 as day
        from dual
        connect by rownum < :enddate - :startdate
    )
select rownum as "S.No", to_date(day,'dd_mm_yyyy') as "Cal_Dt", to_char(day,'day') as "DayName"
from calendar

这篇关于如何在 Oracle 中填充日历表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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