校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識(shí)庫 > oracle獲取上一旬的開始時(shí)間和結(jié)束時(shí)間的實(shí)現(xiàn)函數(shù)

oracle獲取上一旬的開始時(shí)間和結(jié)束時(shí)間的實(shí)現(xiàn)函數(shù)

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

-- 獲取上旬開始時(shí)間
create or replace function fd_lastxunstart(rq in date) return string is
refstr varchar2(50);
v_rq date;
begin
--獲取上一旬的日期
v_rq := trunc(rq);
select case decode(trunc((to_char(v_rq, 'dd') - 1) / 10),
0,
'上旬',
1,
'中旬',
'下旬')
when '上旬' then --返回上個(gè)月的下旬
to_char(add_months(v_rq, -1), 'yyyyMM') || '21'
when '中旬' then
to_char(v_rq, 'yyyymm') || '01' else 
to_char(v_rq, 'yyyymm') || '11'
end
into refstr
from dual;
return refstr;
end fd_lastxunstart;

-- 這個(gè)返回的是:上旬的開始日期
select sysdate from dual;
select fd_lastxunstart(sysdate) from dual;
select fd_lastxunstart(to_date('20130305','yyyymmdd')) from dual;
select fd_lastxunstart(to_date('20130311','yyyymmdd')) from dual;
select fd_lastxunstart(to_date('20130325','yyyymmdd')) from dual;

-- 執(zhí)行結(jié)果為: 2013/9/5 12:08:39、20130821、20130221、20130301、20130311

---- 獲取上一旬的結(jié)束日期
-- 傳遞進(jìn)去 一個(gè) date 類型的值,返回一個(gè)varchar類型的上旬結(jié)束日期
create or replace function fd_lastxunend(rq in date) return string is
refstr varchar2(50);
v_rq date;
begin
--獲取上一旬的日期
v_rq := trunc(rq);
select case decode(trunc((to_char(v_rq, 'dd') - 1) / 10),
0,
'上旬',
1,
'中旬',
'下旬')
when '上旬' then --返回上個(gè)月的最后1天
--chr(39) 這個(gè)是加引號(hào)
to_char(last_day(add_months(v_rq, -1)) + 1 - 1 / 24 / 60 / 60,
'yyyymmdd')
when '中旬' then
to_char(v_rq, 'yyyymm') || '10' else 
to_char(v_rq, 'yyyymm') || '20'
end
into refstr
from dual;
return refstr;
end fd_lastxunend;

-- 這個(gè)獲取的是:上旬的結(jié)束日期
select fd_lastxunend(sysdate) from dual;
select fd_lastxunend(to_date('20130305','yyyymmdd')) from dual;
select fd_lastxunend(to_date('20130311','yyyymmdd')) from dual;
select fd_lastxunend(to_date('20130315','yyyymmdd')) from dual;
select fd_lastxunend(to_date('20130221','yyyymmdd')) from dual;

--執(zhí)行結(jié)果:20130831、20130228、20130310、20130310、20130220

-- 觀察 1 / 24 / 60 / 60 的作用 這個(gè)是一秒
select last_day(add_months(trunc(sysdate), -1)) + 1 - 1 / 24 / 60 / 60
from dual;
select last_day(add_months(trunc(sysdate), -1)) from dual;
select last_day(add_months(trunc(sysdate), -1)) + 1 from dual;
-- 執(zhí)行結(jié)果:2013/8/31 23:59:59、2013/8/31、2013/9/1
您可能感興趣的文章:
  • oracle中得到一條SQL語句的執(zhí)行時(shí)間的兩種方式
  • oracle 日期時(shí)間函數(shù)使用總結(jié)
  • oracle日期時(shí)間型timestamp的深入理解
  • Oracle時(shí)間日期操作方法小結(jié)
  • oracle 時(shí)間格式的調(diào)整
  • Oracle關(guān)于時(shí)間/日期的操作
  • 修改計(jì)算機(jī)名或IP后Oracle10g服務(wù)無法啟動(dòng)的解決方法
  • 計(jì)算機(jī)名稱修改后Oracle不能正常啟動(dòng)問題分析及解決
  • Oracle通過時(shí)間(分鐘)計(jì)算有幾天幾小時(shí)幾分鐘的方法

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

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《oracle獲取上一旬的開始時(shí)間和結(jié)束時(shí)間的實(shí)現(xiàn)函數(shù)》,本文關(guān)鍵詞  oracle,獲取,上一,旬,的,開始,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《oracle獲取上一旬的開始時(shí)間和結(jié)束時(shí)間的實(shí)現(xiàn)函數(shù)》相關(guān)的同類信息!
  • 本頁收集關(guān)于oracle獲取上一旬的開始時(shí)間和結(jié)束時(shí)間的實(shí)現(xiàn)函數(shù)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 浦江县| 调兵山市| 嘉兴市| 苏尼特左旗| 武山县| 辉南县| 沅江市| 阿图什市| 军事| 青河县| 合江县| 晋州市| 卢氏县| 会泽县| 南岸区| 奉贤区| 清丰县| 屏山县| 临武县| 石棉县| 冷水江市| 黔西县| 望江县| 淮北市| 九龙坡区| 抚远县| 红河县| 合江县| 阿勒泰市| 曲周县| 玉林市| 长沙县| 秦安县| 正阳县| 福鼎市| 搜索| 金溪县| 新化县| 错那县| 巍山| 新丰县|