Oracle 取上周一到周末日期的查询语句
-- Oracle 取上周一到周末的sql -- 这样取的是 在一周内第几天,是以周日为开始的
select to_char(to_date('20130906','yyyymmdd'),'d') from dual;
--结果:6 注释:2013.09.06是周五,为本周的第六天 select to_char(sysdate+(2-to_char(sysdate,'d'))-7,'yyyymmdd') from dual;---上周一
select to_char(sysdate+(2-to_char(sysdate,'d'))-1,'yyyymmdd') from dual;---上周日 -- 一个更简单的写法 , 返回date类型
select trunc(sysdate,'iw') - 7 from dual;---上周一
select trunc(sysdate,'iw') - 1 from dual;--上周日 -- 这样查出来是本周一
select trunc(sysdate,'iw') from dual; select trunc(to_date('20130915','yyyymmdd'),'iw') from dual;
-- 结果:2013/9/9 注释:20130915 为周日 -- 返回char类型
select to_char(trunc(sysdate,'iw') - 7,'yyyymmdd') from dual;--上周一
select to_char(trunc(sysdate,'iw') - 1,'yyyymmdd') from dual;--上周日 -- 获取上周一的函数
create or replace function fun_acc_getlastweekstart(systemdate in date)
return varchar2 is
result_str varchar2(15);
begin
select to_char(trunc(systemdate, 'iw') - 7, 'yyyymmdd')
into result_str
from dual;
return result_str;
end fun_acc_getlastweekstart; -- 获取上周日的函数
create or replace function fun_acc_getlastweekend(systemdate in date) return varchar2 is
result_str varchar2(15);
begin
select to_char(trunc(systemdate, 'iw') - 1, 'yyyymmdd')
into result_str
from dual;
return result_str;
end fun_acc_getlastweekend; -- 测试这个函数
select fun_acc_getlastweekstart(sysdate) from dual;
select fun_acc_getlastweekend(sysdate) from dual;
select fun_acc_getlastweekstart(to_date('20130915','yyyymmdd')) from dual;
select fun_acc_getlastweekend(to_date('20130915','yyyymmdd')) from dual;
--查询结果:20130826、20130901、20130902、20130908
-- 注:
select sysdate from dual;
--查询结果:2013/9/6 9:45:14
Oracle 取上周一到周末日期的查询语句的更多相关文章
- (转)Oracle 获取上周一到周末日期的查询sql语句
-- Oracle 取上周一到周末的sql -- 这样取的是 在一周内第几天,是以周日为开始的 select to_char(to_date('20130906','yyyymmdd'),'d') f ...
- Oracle 取上周一到周末的sql
-- 这样取的是 在一周内第几天,是以周日为开始的 select to_char(to_date('20131005','yyyymmdd'),'d') from dual; --结果:7 注释:20 ...
- oracle 实现多字段匹配一个关键字查询语句
oracle 实现多字段匹配一个关键字查询语句:有两种方法(经测试,10g中不能用,11g才行): 第一种. select * from table where ('字段名1' ||'字段名2' || ...
- ORACLE中关于表的一些特殊查询语句
1: 如何判断字段的值里面:那些数据包含小写字母或大小字母 判断字段NAME的值里面有小写字母的记录 方式1: SELECT NAME FROM TEST WHERE regexp_like(NAME ...
- Oracle学习(一):基本操作和基本查询语句
文中以"--"开头的语句为凝视,即为绿色部分 1.知识点:能够对比以下的录屏进行阅读 SQL> --录屏工具spool,開始录制,并指定保存路径为c:\基本查询.txt SQ ...
- SQLSERVER 获取datetime日期的查询语句
SELECT varchar(10:57AM SELECT varchar(CONVERT(100), GETDATE(), 2): 11.05.16 SELECT varchar(CONVERT(1 ...
- Mysql中类似于Oracle中connect by ... start with的查询语句(木大看懂)
表结构 create table sys_branch ( id ) not null, parent_id ), branch_name ), delete_flag ), primary key ...
- 这里我们介绍的是 40+ 个非常有用的 Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询。这些是所有 Oracle 开发者都必备的技能,所以快快收藏吧!
日期/时间 相关查询 获取当前月份的第一天 运行这个命令能快速返回当前月份的第一天.你可以用任何的日期值替换 “SYSDATE”来指定查询的日期. SELECT TRUNC (SYSDATE, 'MO ...
- 45 个非常有用的 Oracle 日期查询语句
日期/时间 相关查询 获取当前月份的第一天 运行这个命令能快速返回当前月份的第一天.你可以用任何的日期值替换 “SYSDATE”来指定查询的日期. SELECT TRUNC (SYSDATE, 'MO ...
随机推荐
- hdoj 3400 三分
两次三分 #include <iostream> #include <cstdio> #include <cstring> #include <cmath&g ...
- UVA 673 (13.08.17)
Parentheses Balance You are given a string consisting of parentheses () and []. Astring of this ty ...
- java RMI入门指南
感觉这篇文章不错,直接转了 RMI全称是Remote Method Invocation-远程方法调用,Java RMI在JDK1.1中实现的,其威力就体如今它强大的开发分布式网络应用的能力上,是纯J ...
- 自增运算a++和++b(1)
#include<reg52.h> #define uint unsigned int #define uchar unsigned char uchar code f[]={0x3f,0 ...
- Ubuntu 系统 文件操作命令
文件和目录的操作 用户主目录下有一个 Desktop (对应,桌面)mkdir dir1 建立一个目录cd 不添加参数,默认回到主目录(用户目录)touch a.txt 建立一个文件mv a.txt ...
- js控制html5 audio的暂停、播放、停止
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name ...
- C# 获取配置文件节点值
<?xml version="1.0" encoding="utf-8" ?><configuration> <appSetti ...
- django表单及母板
在之前的埔文中说到了对Model的操作以及对url的路由映射等内容,对应django的mtv框架则是完成了学习,Model与viewer的操作,那么本节主要来唠叨一下template,当Model,v ...
- 1207--ATM自动取款机的实现
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> //提示用户操作 void alert(ch ...
- UILable文本常见属性说明
1.text:设置标签显示文本. 2.attributedText:设置标签属性文本. NSString *text = @"first"; NSMutableAttributed ...