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 ...
随机推荐
- Linux 安装配置JDK 、 MySQL 、nginx
今天我来讲一下在Linux下各环境的搭建,主要就讲一下jdk.MySQL.和一个代理服务器nginx 1. jdk的安装配置 1)卸载自带openjdk 当我们拿到一个全新的ECS的时候上面有的会自带 ...
- 关于函数提升在if语句中的表现
函数声明创建的函数在现代浏览器,在if语句中函数的声明不会提升,但是在老的IE版本中,if语句中的函数声明会提升 函数表达式在不同浏览器中函数声明都不会被提升,解决了不同浏览器的兼容性问题 关于函数提 ...
- WebService的概念
一.序言 大家或多或少都听过 WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成 分.但是不得不承认的是W ...
- SQLServer2008 关于Having
转自百度百科 与where 相比 HAVING 子句对 GROUP BY 子句设置条件的方式与 WHERE 子句和 SELECT 语句交互的方式类似. WHERE 子句搜索条件在进行分组操作之前应用: ...
- VHDL之concurrent之operators
Using operators Operators can be used to implement any combinational circuit. However, as will becom ...
- VS2012 +OpenCv2.4.4配置
使用OpenCV少了数据读取.填充.存储的麻烦. 转载于opencv官网:对于2010和2.43的配置可以直接挪用到新配置环境 http://www.opencv.org.cn/index.php/V ...
- mvc重定向
出处 : https://www.cnblogs.com/lgxlsm/p/5441149.html .重定向方法:Redirect / RedirectToAction / RedirectToRo ...
- class path resource [processes/] cannot be resolved to URL because it does not exist
springboot整合activiti时报以下错误,原因是项目启动时检查流程文件 nested exception is java.io.FileNotFoundException: class p ...
- BZOJ 3012: [Usaco2012 Dec]First! 字典树 + tarjan
Code: #include<bits/stdc++.h> #define maxn 1000003 using namespace std; char str[maxn],strtot[ ...
- 为什么多 TCP 连接比单 TCP 连接传输快
转自: 我观察到,客户端机器从单一服务器使用 HTTP 下载一个文件:1. 单连接下载,速度没有达到客户端网络的最大带宽:2. 多连接同时下载,传输速度有极大的提高,带宽被占满. 假设如下前提:1. ...