您好,登錄后才能下訂單哦!
本文小編為大家詳細(xì)介紹“SQL常用日期查詢(xún)語(yǔ)句及顯示格式設(shè)置是什么”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“SQL常用日期查詢(xún)語(yǔ)句及顯示格式設(shè)置是什么”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來(lái)學(xué)習(xí)新知識(shí)吧。
SELECT TO_CHAR(SYSDATE,'YYYY') AS YEAR FROM DUAL--查詢(xún)當(dāng)前年份 SELECT TO_CHAR(SYSDATE,'YYY') AS YEAR FROM DUAL--查詢(xún)當(dāng)前年份后兩位 SELECT TO_CHAR(SYSDATE,'YY') AS YEAR FROM DUAL--查詢(xún)當(dāng)前年份最后兩位 SELECT TO_CHAR(SYSDATE,'Y') AS YEAR FROM DUAL--查詢(xún)當(dāng)前年份最后一位
SELECT TO_CHAR(SYSDATE,'DDD') AS DAYS FROM DUAL
SELECT TO_CHAR(SYSDATE,'DD') AS DAYS FROM DUAL
SELECT TO_CHAR(SYSDATE,'dy') AS WEEK FROM DUAL SELECT TO_CHAR(SYSDATE,'day') AS WEEK FROM DUAL
SELECT TO_CHAR(SYSDATE,'DDD') AS DAYS FROM DUAL
SELECT TO_CHAR(SYSDATE,'Q') AS JD FROM DUAL
SELECT TO_CHAR(SYSDATE,'IW') AS WEEKNUM FROM DUAL SELECT TO_CHAR(SYSDATE,'WW') AS WEEKNUM FROM DUAL SELECT TO_CHAR(SYSDATE,'W') AS WEEKNUM FROM DUAL
SELECT TO_CHAR(last_day(to_date('2019/02/01','YYYY/MM/DD')),'DD') AS MONTH_DAYS_NUMBER FROM DUAL
SELECT TO_CHAR(SYSDATE,'YYYY/MM/DD') AS MONTH FROM DUAL--獲取當(dāng)前日期的'YYYY/MM/DD'格式:2020/01/02 SELECT TO_CHAR(SYSDATE,'YYYYMMDD') AS MONTH FROM DUAL--獲取當(dāng)前日期的'YYYYMMDD'格式:20200102 SELECT TO_CHAR(SYSDATE,'YYYYMMDD HH:MI:SS') AS now FROM DUAL--獲取當(dāng)前時(shí)間,精確到秒的12小時(shí)制格式:20200102 03:18:25 SELECT TO_CHAR(SYSDATE,'YYYYMMDD HH24:MI:SS') AS now FROM DUAL--獲取當(dāng)前時(shí)間,精確到秒24小時(shí)制的格式:20200102 15:18:13 SELECT TO_CHAR(SYSDATE,'YYYY/MM/DD HH24:MI:SS:PM:DY') AS now FROM DUAL--獲取當(dāng)前時(shí)間的格式,顯示上、下午和星期幾:2020/01/02 15:17:59:下午:星期四
SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7' second,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢(xún)當(dāng)前時(shí)間的7秒前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7' minute,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢(xún)當(dāng)前時(shí)間的7分鐘前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7'hour ,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢(xún)當(dāng)前時(shí)間的7小時(shí)前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7'day ,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢(xún)當(dāng)前時(shí)間的7天前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7'month ,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢(xún)當(dāng)前時(shí)間的7月前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7'year ,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢(xún)當(dāng)前時(shí)間的7年前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - 8*INTERVAL '7'hour ,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢(xún)當(dāng)前時(shí)間參數(shù)年、月、日、時(shí)、分、秒乘以一個(gè)數(shù)字倍數(shù)之前的時(shí)間
讀到這里,這篇“SQL常用日期查詢(xún)語(yǔ)句及顯示格式設(shè)置是什么”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過(guò)才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。