Oracle's date functions

a system time

1. Grammar
SYSDATE
Default format: DD-MON-RR (day month year)
2. Examples
  1. SQL>select sysdate from dual;
  2. SYSDATE
  3. --------------
  4. 02-7-17
two-day operation
1. Grammar
ADD_MONTHS(date,i): Returns the month added to the specified date.
i can be any integer, if i is a decimal, the integer part is truncated
If i is negative, it is equivalent to subtracting the month from the original date.
NEXT_DAY (date,char)
If the value of char is 'Monday', returns the next Monday hour of the date specified by date.
LAST_DAY(date): Returns the last day of each month.
MONTH_BETWEEN(date1,date2)
EXTRACT(date from datetime)
2. Examples
  1. SQL>select add_months(sysdate,3),add_months(sysdate,-3)from dual;
  2. ADD_MONTHS(SYS ADD_MONTHS(SYS
  3. ----------------------------
  4. 02-10月-1702-4-17
  5. SQL>select next_day(sysdate,'星期一')from dual;
  6. NEXT_DAY(SYSDA
  7. --------------
  8. 03-7-17
  9. SQL>select next_day(sysdate,'星期日')from dual;
  10. NEXT_DAY(SYSDA
  11. --------------
  12. 09-7-17
  13. SQL>select last_day(sysdate)from dual;
  14. LAST_DAY(SYSDA
  15. --------------
  16. 31-7-17
  17. SQL>select month_betweens('20-5月-15','10-1月-15')from dual;
  18. select month_betweens('20-5月-15','10-1月-15')from dual
  19. *
  20. 1行出现错误:
  21. ORA-00904:"MONTH_BETWEENS":标识符无效
  22. SQL>select months_between('20-5月-15','10-1月-15')from dual;
  23. MONTHS_BETWEEN('20-5月-15','10-1月-15')
  24. ---------------------------------------
  25. 4.32258065
  26. SQL>select extract(year from sysdate)from dual;
  27. EXTRACT(YEARFROMSYSDATE)
  28. ------------------------
  29. 2017
  30. SQL>select extract(month from sysdate)from dual;
  31. EXTRACT(MONTHFROMSYSDATE)
  32. -------------------------
  33. 7
  34. SQL>select extract(day from sysdate)from dual;
  35. EXTRACT(DAYFROMSYSDATE)
  36. -----------------------
  37. 2
  38. SQL>select extract(hour from timestamp '2017-10-1 17:24:34')from dual;
  39. EXTRACT(HOURFROMTIMESTAMP'2017-10-117:24:34')
  40. ---------------------------------------------
  41. 17
  42. SQL>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326189184&siteId=291194637