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 ...
随机推荐
- MySQL-基础操作之增删改查
1.增 (1)创建数据库dks create database dks; (2)创建名为t1的表,并指定引擎和字符集: ) not null,ages int) engine=innodb defau ...
- 工具分享1:文本编辑器EditPlus、汇编编译器masm、Dos盒子
工具已打包好,需要即下载 链接 https://pan.baidu.com/s/1dvMyvW 密码 mic4
- 基于CGAL的Delaunay三角网应用
目录 1. 背景 1.1 CGAL 1.2 cgal-bindings(Python包) 1.3 vtk-python 1.4 PyQt5 2. 功能设计 2.1 基本目标 2.2 待实现目标 3. ...
- iOS多线程——GCD篇
什么是GCD GCD是苹果对多线程编程做的一套新的抽象基于C语言层的API,结合Block简化了多线程的操作,使得我们对线程操作能够更加的安全高效. 在GCD出现之前Cocoa框架提供了NSObjec ...
- Spring logger 配置
1. logback-spring.xml <?xml version="1.0" encoding="UTF-8"?> <configura ...
- electron 学习
index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- MAVEN - 生命周期(1)
三套生命周期: MAVEN拥有三套互相独立的生命周期,分别是:clean.default和site. clean - 清理项目 default - 构建项目 site - 简历项目站点 这其中 ...
- QS之force(3)
Example in project - First force signals in certain time and then noforce signals after some time. # ...
- 利用jsonp进行Ajax跨域请求
在进行Ajax请求的时候经常会遇到跨域的问题,这个时候一般就会用到jsonp. 关于json和jsonp,网上有很多原理解释,这里就不多赘述,需要的自行搜索. 下面是一个简单的ajax跨域请求示例: ...
- DNN:windows使用 YOLO V1,V2
本文有修改,如有疑问,请移步原文. 原文链接: YOLO v1之总结篇(linux+windows) 此外: YOLO-V2总结篇 Yolo9000的改进还是非常大的 由于原版的官方YOLOv ...