濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > Oracle 獲取上周一到周末日期的查詢sql語(yǔ)句

Oracle 獲取上周一到周末日期的查詢sql語(yǔ)句

熱門(mén)標(biāo)簽:word地圖標(biāo)注方向 征服眼公司地圖標(biāo)注 美圖秀秀地圖標(biāo)注 開(kāi)封智能外呼系統(tǒng)廠家 人工智能地圖標(biāo)注自己能做嗎 百度地圖標(biāo)注素材 外呼線路外顯本地號(hào)碼 征服者火車站地圖標(biāo)注 阿爾巴尼亞地圖標(biāo)注app
復(fù)制代碼 代碼如下:

-- Oracle 取上周一到周末的sql

-- 這樣取的是 在一周內(nèi)第幾天,是以周日為開(kāi)始的
select to_char(to_date('20130906','yyyymmdd'),'d') from dual;
--結(jié)果: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;---上周日

-- 一個(gè)更簡(jiǎn)單的寫(xiě)法 , 返回date類型
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 注釋:20130915 為周日

-- 返回char類型
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;
--查詢結(jié)果:20130826、20130901、20130902、20130908
-- 注:
select sysdate from dual;
--查詢結(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日期分組查詢的完整實(shí)例

標(biāo)簽:泰安 海北 宜春 六安 孝感 葫蘆島 酒泉 淮南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Oracle 獲取上周一到周末日期的查詢sql語(yǔ)句》,本文關(guān)鍵詞  Oracle,獲取,上周,一到,周末,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Oracle 獲取上周一到周末日期的查詢sql語(yǔ)句》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Oracle 獲取上周一到周末日期的查詢sql語(yǔ)句的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    汉川市| 阳东县| 航空| 淮北市| 乌兰察布市| 上饶县| 满洲里市| 孟村| 石林| 桂林市| 专栏| 河源市| 乌苏市| 兖州市| 甘德县| 平阴县| 榕江县| 三江| 松江区| 驻马店市| 九龙城区| 多伦县| 石楼县| 长海县| 讷河市| 黎川县| 乌海市| 富蕴县| 德昌县| 邵武市| 芮城县| 凤凰县| 调兵山市| 昭苏县| 三门县| 中卫市| 朔州市| 浮山县| 大田县| 定陶县| 诏安县|