oralce sql 创建指定时间段内的日历信息
-- Create table
create table TEMP_CALENDAR
(
MONTH VARCHAR2(6),
W_7 VARCHAR2(2),
W_1 VARCHAR2(2),
W_2 VARCHAR2(2),
W_3 VARCHAR2(2),
W_4 VARCHAR2(2),
W_5 VARCHAR2(2),
W_6 VARCHAR2(2),
WEEK VARCHAR2(20)
) ;
-- Add comments to the table
comment on table TEMP_CALENDAR
is '日期源数据表';
-- Add comments to the columns
comment on column TEMP_CALENDAR.MONTH
is '月份(格式如:200801)';
comment on column TEMP_CALENDAR.W_7
is '周日的日期(如:06)';
comment on column TEMP_CALENDAR.W_1
is '周一(如:07)';
comment on column TEMP_CALENDAR.W_2
is '周二(如:08)';
comment on column TEMP_CALENDAR.W_3
is '周三(如:09)';
comment on column TEMP_CALENDAR.W_4
is '周四(如:10)';
comment on column TEMP_CALENDAR.W_5
is '周五(如:11)';
comment on column TEMP_CALENDAR.W_6
is '周六(如:12)';
comment on column TEMP_CALENDAR.WEEK
is '本月第几周';
----生成 日历信息
-- truncate table calendar;
declare
vi_begin_year number(6);
vi_end_year number(6);
vi_year number(6);
vi_month number(6);
vs_month varchar2(6);
vs_first_day varchar2(8);
begin
vi_begin_year :=2000; ---start year
vi_end_year :=2100; --- end year
vi_month :=1;
vi_year := vi_begin_year;
loop exit when(vi_year > vi_end_year);
for i in 1..12 loop
if length(i) =1 then
vs_month := to_char(vi_year)||'0'||to_char(i);
else
vs_month := to_char(vi_year)||to_char(i);
end if;
vs_first_day := vs_month||'01';
insert into temp_calendar ( month, week,w_7, w_1, w_2, w_3, w_4, w_5, w_6 )
select substr(vs_first_day,1,6) month,
ceil((to_char(everyday,'dd')+(to_char(to_date(vs_first_day,'yyyymmdd'),'d')-1))/7) as week,
sum(decode(to_char(everyday,'dy'),'星期日',to_char(everyday,'dd'))) as 星期日,
sum(decode(to_char(everyday,'dy'),'星期一',to_char(everyday,'dd'))) as 星期一,
sum(decode(to_char(everyday,'dy'),'星期二',to_char(everyday,'dd'))) as 星期二,
sum(decode(to_char(everyday,'dy'),'星期三',to_char(everyday,'dd'))) as 星期三,
sum(decode(to_char(everyday,'dy'),'星期四',to_char(everyday,'dd'))) as 星期四,
sum(decode(to_char(everyday,'dy'),'星期五',to_char(everyday,'dd'))) as 星期五,
sum(decode(to_char(everyday,'dy'),'星期六',to_char(everyday,'dd'))) as 星期六
from(
select to_date(vs_first_day,'yyyymmdd') + level - 1 as everyDay
from dual
connect by level <= (last_day(to_date(vs_first_day,'yyyymmdd'))
- to_date(vs_first_day,'yyyymmdd') +1) )
group by ceil((to_char(everyday,'dd')+(to_char(to_date(vs_first_day,'yyyymmdd'),'d')-1))/7) ;
commit;
end loop;
vi_year := vi_year+1;
end loop;
end;
order by a.year,a.month, a.week;
oralce sql 创建指定时间段内的日历信息的更多相关文章
- sql取指定时间段内的所有月份
declare @begin datetime,@end datetime set @begin='2017-01-01' set @end='2019-03-04' declare @months ...
- sqlServer通过指定的起始时间,创建该时间段内以年、月、日为时间段的临时表
通过指定的起始时间,创建该时间段内以年.月.日为时间段的临时表 ALTER PROCEDURE [dbo].[YOUR_SP_Name] -- Add the parameters for t ...
- 趣味SQL——创建指定的数据类型
原创作品,出自 "深蓝的blog" 博客,深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/46908843 趣味 ...
- SQL Server备份时间段内插入的数据依旧进入了备份文件?(转载)
问 MSSql我在本机测试了下.为了延长备份时间,找个大的数据库.开始完整备份bak然后再此库新建表,并增添数据.备份结束.==================还原备份后,在还原的数据库内发现新增的表 ...
- shell查找指定时间段内的文件
#!/bin/bash#20170905 输入参数格式echo "显示"$1"的备份文件"date_0=$1date_1=`expr $date_0 + 1`d ...
- SQL Server中获取指定时间段内的所有日期
DECLARE @days INT, @date_start DATETIME = '2016-11-01', @date_end DATETIME = '2016-11-10' SET @days ...
- 数据库SQL语句查询指定时间段内的数据
[摘要]有的时候,我们需要查询数据库某段时间之间的数据,比如2016年5月1号到到5月3号之间用户注册数量(特殊节假日期间)等.那么用SQL语句如何实现呢? 首先,数据表中的存时间的字段比如是addt ...
- SQL Server中获取指定时间段内的所有月份
例如查询 2012-1-5 到 2012-11-3 之间所有的月份 declare @begin datetime,@end datetime set @begin='2012-1-5' set @e ...
- SQL Server 查询时间段内数据
方式一: ALTER Proc [dbo].[usp_Rpt_AcctTypeAudit] @FromDate datetime=null, -- yyyy-mm-dd (may change in ...
随机推荐
- 二进制部署Kubernetes-v1.14.1集群
一.部署Kubernetes集群 1.1 Kubernetes介绍 Kubernetes(K8S)是Google开源的容器集群管理系统,K8S在Docker容器技术的基础之上,大大地提高了容器化部署应 ...
- JS——事件详情(鼠标事件:clientX、clientY的用法)
鼠标位置 >可视区位置:clientX.clientY 跟着鼠标移动的div案例 代码如下图: 这个案例,运用到前一篇文章中的event事件来处理.获取div的left和top值,当鼠标移动 ...
- 牛客练习赛19 -E-托米的饮料
题目描述 好了,现在是小托米的故事啦~~~ 可爱的小托米得到了n瓶饮料. 但他不小心把开盖的工具弄丢了,所以他只能利用饮料瓶来开盖. 已知第i个瓶子的品牌为ai,且其能打开bi品牌的瓶子. 问有几瓶饮 ...
- 一周代码秀之[11.18~11.24 linq2xml面向对象]
1.xml <Sections> <Item key ="1" value ="孕哺期" canBeSelected="false& ...
- 通过getSystemServices获取手机管理大全
getSystemService是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象.以下介绍系统相应的服务. 传入 ...
- dapper.net 存储过程
var param = new DynamicParameters(); param.Add(); param.Add(); param.Add(, DbType.Int32, ParameterDi ...
- (转)C#开发微信门户及应用(6)--微信门户菜单的管理操作
http://www.cnblogs.com/wuhuacong/p/3701961.html 前面几篇继续了我自己对于C#开发微信门户及应用的技术探索和相关的经验总结,继续探索微信API并分享相关的 ...
- maven多个子项目、父项目之间的引用问题
在项目时用到maven管理项目,在一个就项目的基础上开发新的项目:关于子项目和父项目,子项目与子项目之间的调用问题,发现自己存在不足,以下是自己查询的问题,解决了自己的疑惑. 问题 下面是一个简略的项 ...
- vs2008 打开项目 无法读取项目文件
卸载vs2015之后 出现问题 C:\Windows\SysWOW64\regedit.exe 64系统运行这个 删除 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MS ...
- Java设计模式之JDK动态代理原理
动态代理核心源码实现public Object getProxy() { //jdk 动态代理的使用方式 return Proxy.newProxyInstance( this.getClass(). ...