1.查詢當(dāng)前年、月、周相關(guān)時(shí)間
1.1.查詢當(dāng)前年份
SELECT TO_CHAR(SYSDATE,'YYYY') AS YEAR FROM DUAL--查詢當(dāng)前年份
SELECT TO_CHAR(SYSDATE,'YYY') AS YEAR FROM DUAL--查詢當(dāng)前年份后兩位
SELECT TO_CHAR(SYSDATE,'YY') AS YEAR FROM DUAL--查詢當(dāng)前年份最后兩位
SELECT TO_CHAR(SYSDATE,'Y') AS YEAR FROM DUAL--查詢當(dāng)前年份最后一位
1.2.查詢當(dāng)前年份第幾天
SELECT TO_CHAR(SYSDATE,'DDD') AS DAYS FROM DUAL
1.3.查詢當(dāng)前月份第幾天
SELECT TO_CHAR(SYSDATE,'DD') AS DAYS FROM DUAL
1.4.查詢當(dāng)前周的星期幾
SELECT TO_CHAR(SYSDATE,'dy') AS WEEK FROM DUAL
SELECT TO_CHAR(SYSDATE,'day') AS WEEK FROM DUAL
2.查詢當(dāng)前第幾季度
SELECT TO_CHAR(SYSDATE,'Q') AS JD FROM DUAL
3.查詢當(dāng)前在一年內(nèi)是第幾周
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
4.查詢當(dāng)前某年某月有多少天
SELECT TO_CHAR(last_day(to_date('2019/02/01','YYYY/MM/DD')),'DD') AS MONTH_DAYS_NUMBER FROM DUAL
5.查詢當(dāng)前的日期格式
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:下午:星期四
6.查詢距離當(dāng)前時(shí)間一段時(shí)間間隔的時(shí)間,當(dāng)前時(shí)間之前用“-”當(dāng)前時(shí)間之后用“+”
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 --查詢當(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 --查詢當(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 --查詢當(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 --查詢當(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 --查詢當(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 --查詢當(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 --查詢當(dāng)前時(shí)間參數(shù)年、月、日、時(shí)、分、秒乘以一個(gè)數(shù)字倍數(shù)之前的時(shí)間
以上就是oracle 日期操作語(yǔ)句總結(jié)的詳細(xì)內(nèi)容,更多關(guān)于oracle 日期操作的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
您可能感興趣的文章:- ORACLE中的日期加減操作實(shí)例介紹
- Oracle時(shí)間日期操作方法小結(jié)
- Oracle關(guān)于時(shí)間/日期的操作