麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 數據庫 > Oracle > 正文

oracle獲取上一旬的開始時間和結束時間的實現函數

2024-08-29 13:57:02
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:


-- 獲取上旬開始時間
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 --返回上個月的下旬
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;

-- 這個返回的是:上旬的開始日期
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;

-- 執行結果為: 2013/9/5 12:08:39、20130821、20130221、20130301、20130311

---- 獲取上一旬的結束日期
-- 傳遞進去 一個 date 類型的值,返回一個varchar類型的上旬結束日期
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 --返回上個月的最后1天
--chr(39) 這個是加引號
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;

-- 這個獲取的是:上旬的結束日期
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;

--執行結果:20130831、20130228、20130310、20130310、20130220

-- 觀察 1 / 24 / 60 / 60 的作用 這個是一秒
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;
-- 執行結果:2013/8/31 23:59:59、2013/8/31、2013/9/1

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高清av在线| 久久国产精品久久久久久电车 | 久久精片 | 久久久三区 | 国产91在线亚洲 | 毛片免费观看视频 | 作爱在线观看 | 羞羞视频入口 | 一级看片免费视频 | 人人玩人人爽 | 亚洲va久久久噜噜噜久久男同 | 丰满年轻岳中文字幕一区二区 | 国产亚洲欧美一区久久久在 | 久久久久国产成人精品亚洲午夜 | 午夜在线视频观看 | 中文字幕一区二区三区四区 | 成人午夜在线免费 | 成人性视频在线 | free性欧美hd另类 | 在线a| 欧美中文字幕一区二区三区亚洲 | 久久久电影电视剧免费看 | 中文字幕天堂在线 | 亚洲综合视频在线播放 | 久久成人福利 | av视屏| 久久精品亚洲一区二区三区观看模式 | 国产一区网址 | 成片免费大全 | 国产一国产精品一级毛片 | 午夜丰满少妇高清毛片1000部 | 成年人网站视频免费 | 天天看天天摸天天操 | 免费看日韩片 | 依依成人精品视频 | 亚州精品天堂中文字幕 | 91 在线免费观看 | 亚洲精品午夜电影 | 国产精品久久久久久久亚洲按摩 | 欧美精品电影一区 | 欧美高清另类自拍视频在线看 |