Oracle 獲取上周一到周末日期的查詢(xún)sql語(yǔ)句
-- Oracle 取上周一到周末的sql
-- 這樣取的是 在一周內(nèi)第幾天,是以周日為開(kāi)始的
select to_char(to_date('20130906','yyyymmdd'),'d') from dual;
--結(jié)果:6 注釋?zhuān)?013.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;---上周日
-- 一個(gè)更簡(jiǎn)單的寫(xiě)法 , 返回date類(lèi)型
select trunc(sysdate,'iw') - 7 from dual;---上周一
select trunc(sysdate,'iw') - 1 from dual;--上周日
-- 這樣查出來(lái)是本周一
select trunc(sysdate,'iw') from dual;
select trunc(to_date('20130915','yyyymmdd'),'iw') from dual;
-- 結(jié)果:2013/9/9 注釋?zhuān)?0130915 為周日
-- 返回char類(lèi)型
select to_char(trunc(sysdate,'iw') - 7,'yyyymmdd') from dual;--上周一
select to_char(trunc(sysdate,'iw') - 1,'yyyymmdd') from dual;--上周日
-- 獲取上周一的函數(shù)
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;
-- 獲取上周日的函數(shù)
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;
-- 測(cè)試這個(gè)函數(shù)
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;
--查詢(xún)結(jié)果:20130826、20130901、20130902、20130908
-- 注:
select sysdate from dual;
--查詢(xún)結(jié)果:2013/9/6 9:45:14
- oracle日期時(shí)間型timestamp的深入理解
- Oracle 函數(shù)大全[字符串函數(shù),數(shù)學(xué)函數(shù),日期函數(shù)]
- Oracle插入日期數(shù)據(jù)常見(jiàn)的2個(gè)問(wèn)題和解決方法
- oracle查看當(dāng)前日期是第幾個(gè)星期的方法
- Oracle to_char 日期轉(zhuǎn)換字符串語(yǔ)句分享
- 詳解oracle 日期格式(總結(jié))
- oracle 日期時(shí)間函數(shù)使用總結(jié)
- ORACLE 毫秒與日期的相互轉(zhuǎn)換示例
- oracle 日期函數(shù)集合(集中版本)
- oracle日期分組查詢(xún)的完整實(shí)例
相關(guān)文章
Oracle刪除當(dāng)前用戶(hù)下所有表的方法適用于有或沒(méi)有刪除權(quán)限
如果有plsql客戶(hù)端,則可以使用該用戶(hù)登錄,選中所有表 右鍵Drop即可,如果有或沒(méi)有刪除用戶(hù)的權(quán)限都可以使用下面的方法2014-06-06安裝Oracle完整客戶(hù)端后沒(méi)有訪(fǎng)問(wèn)接口OraOLEDB.Oracle解決辦法
這篇文章主要給大家介紹了關(guān)于安裝Oracle完整客戶(hù)端后沒(méi)有訪(fǎng)問(wèn)接口OraOLEDB.Oracle的解決辦法,文中通過(guò)代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考解決價(jià)值,需要的朋友可以參考下2024-01-01ORACLE 正則解決初使化數(shù)據(jù)格式不一致
在初使化用戶(hù)基礎(chǔ)數(shù)據(jù)時(shí)會(huì)出現(xiàn)一些數(shù)據(jù)格式不正確的情況。。2009-05-05oracle數(shù)據(jù)庫(kù)刪除數(shù)據(jù)Delete語(yǔ)句和Truncate語(yǔ)句的使用比較
oracle當(dāng)表中的數(shù)據(jù)不需要時(shí),則應(yīng)該刪除該數(shù)據(jù)并釋放所占用的空間,刪除表中的數(shù)據(jù)可以使用Delete語(yǔ)句或者Truncate語(yǔ)句,下面分別介紹2012-09-09Oracle 數(shù)據(jù)庫(kù)忘記sys與system管理員密碼重置操作方法
這篇文章主要介紹了Oracle 數(shù)據(jù)庫(kù)忘記sys與system管理員密碼重置操作,需要的朋友可以參考下2017-06-06一文解析ORACLE樹(shù)結(jié)構(gòu)查詢(xún)
這篇文章主要介紹了一文解析ORACLE樹(shù)結(jié)構(gòu)查詢(xún),文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容戒殺,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09Oracle中的Connect/session和process的區(qū)別及關(guān)系介紹
本文將詳細(xì)探討下Oracle中的Connect/session和process的區(qū)別及關(guān)系,感興趣的你可以參考下,希望可以幫助到你2013-03-03Mybatis出現(xiàn)ORA-00911: invalid character的解決辦法
今天在項(xiàng)目中,使用Mybatis對(duì)oracle數(shù)據(jù)庫(kù)進(jìn)行操作的時(shí)候,報(bào)出ORA-00911: invalid character的錯(cuò)誤,檢查了一下SQL,發(fā)現(xiàn)都書(shū)寫(xiě)正確啊,復(fù)制到plsql上執(zhí)行也都沒(méi)問(wèn)題,這什么原因呢,下面通過(guò)本文給大家解答下2016-12-12