日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Oracle 取上周一到周末的sql

系統 2828 0

-- 這樣取的是 在一周內第幾天,是以周日為開始的
select to_char(to_date('20131005','yyyymmdd'),'d') from dual;
--結果:7 注釋:2013.10.05是周六,為本周的第7天


select to_char(sysdate+(2-to_char(sysdate,'d'))-7,'yyyymmdd') from dual;---上周一 //2013.09.23
?select to_char(sysdate+(2-to_char(sysdate,'d'))-1,'yyyymmdd') from dual;---上周日 //2013.09.29


-- 一個更簡單的寫法 , 返回date類型
select trunc(sysdate,'iw') - 7 from dual;---上周一
select trunc(sysdate,'iw') - 1 from dual;--上周日


-- 這樣查出來是本周一
select trunc(sysdate,'iw') from dual;


?select trunc(to_date('20131005','yyyymmdd'),'iw') from dual;
-- 結果:2013/9/30 注釋:20131005 為周六


-- 返回char類型
select to_char(trunc(sysdate,'iw') - 7,'yyyymmdd') from dual;--上周一
select to_char(trunc(sysdate,'iw') - 1,'yyyymmdd') from dual;--上周日


-- 獲取上周一的函數
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;

/



-- 獲取上周日的函數
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;

/



-- 測試這個函數
select fun_acc_getlastweekstart(sysdate) from dual;
?select fun_acc_getlastweekend(sysdate) from dual;
?select fun_acc_getlastweekstart(to_date('20131005','yyyymmdd')) from dual;
?select fun_acc_getlastweekend(to_date('20131005','yyyymmdd')) from dual;
--查詢結果:20130923、20130930、20130923、20130929
-- 注:
select sysdate from dual;
--查詢結果:2013/10/05

?

Oracle 取上周一到周末的sql


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 松桃| 济阳县| 丰城市| 古田县| 射洪县| 勃利县| 商水县| 安庆市| 栖霞市| 辽源市| 芮城县| 临桂县| 鄄城县| 舞阳县| 雅江县| 安义县| 延庆县| 大洼县| 隆德县| 黄龙县| 开阳县| 丰都县| 加查县| 武强县| 阳泉市| 蓝田县| 迁安市| 乃东县| 扬州市| 德钦县| 东海县| 三门峡市| 巴林右旗| 棋牌| 山丹县| 吉木萨尔县| 股票| 景德镇市| 阿尔山市| 伽师县| 亚东县|