国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > Oracle > 正文

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

2020-07-26 14:23:15
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
復(fù)制代碼 代碼如下:

-- 獲取上旬開(kāi)始時(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è)返回的是:上旬的開(kāi)始日期
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
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 崇阳县| 伊宁县| 东兴市| 偃师市| 合水县| 萝北县| 诸暨市| 光山县| 晋州市| 上犹县| 安国市| 阿城市| 珠海市| 邹平县| 靖安县| 北安市| 东台市| 朔州市| 满城县| 当阳市| 许昌县| 襄樊市| 壤塘县| 辽阳县| 丰都县| 左贡县| 铁岭县| 曲沃县| 赤水市| 安福县| 溧阳市| 兴国县| 柳林县| 海口市| 铁力市| 黔西| 七台河市| 应城市| 开封县| 长岛县| 安多县|