Oracle Date / Time Function

 -- sysdate 


SELECT sysdate from dual

SYSDATE
2022/02/22


-- systimestamp 


SELECT systimestamp from dual


SYSTIMESTAMP
22-2月 -22 01.28.54.849788 上午 +00:00



-- add_months 
SELECT add_months('2022/02/22', 3)
from dual

ADD_MONTHS('2022/02/22',3)
2022/05/22


SELECT add_months('2022/02/22', -3)
from dual
ADD_MONTHS('2022/02/22',-3)
2021/11/22



-- months_between 

SELECT months_between('2022/02/15', '2023/02/15')
from dual
MONTHS_BETWEEN('2022/02/15','2023/02/15')
-12


--加入trunc

SELECT trunc(systimestamp) from dual
TRUNC(SYSTIMESTAMP)
2022/02/22


SELECT trunc(systimestamp, 'YEAR') from dual
TRUNC(SYSTIMESTAMP,'YEAR')
2022/01/01



SELECT trunc(systimestamp, 'MONTH') from dual
TRUNC(SYSTIMESTAMP,'MONTH')
2022/02/01

0 Comments:

張貼留言