Posted By

bbrumm on 02/18/17


Tagged

sql Oracle


Versions (?)

Oracle EXTRACT Function


 / Published in: SQL
 

URL: http://www.databasestar.com/oracle-extract/

A few examples of the EXTRACT function.

  1. --Example 1
  2. SELECT SYSDATE,
  3. EXTRACT(YEAR FROM SYSDATE) AS EXTRACT_EXAMPLE
  4. FROM dual;
  5.  
  6. --Example 2
  7. SELECT SYSDATE,
  8. EXTRACT(MONTH FROM SYSDATE) AS EXTRACT_EXAMPLE
  9. FROM dual;
  10.  
  11. --Example 3
  12. SELECT SYSDATE,
  13. EXTRACT(DAY FROM SYSDATE) AS EXTRACT_EXAMPLE
  14. FROM dual;
  15.  
  16. --Example 4
  17. SELECT SYSDATE,
  18. EXTRACT(HOUR FROM SYSDATE) AS EXTRACT_HOUR
  19. FROM dual;
  20.  
  21. --Example 5
  22. SELECT SYSTIMESTAMP,
  23. EXTRACT(HOUR FROM SYSTIMESTAMP) AS EXTRACT_HOUR,
  24. EXTRACT(MINUTE FROM SYSTIMESTAMP) AS EXTRACT_MINUTE,
  25. EXTRACT(SECOND FROM SYSTIMESTAMP) AS EXTRACT_SECOND
  26. FROM dual;
  27.  
  28. --Example 6
  29. SELECT SYSTIMESTAMP,
  30. EXTRACT(TIMEZONE_HOUR FROM SYSTIMESTAMP) AS EXTRACT_TIMEZONE_HOUR,
  31. EXTRACT(TIMEZONE_MINUTE FROM SYSTIMESTAMP) AS EXTRACT_TIMEZONE_MINUTE,
  32. EXTRACT(TIMEZONE_REGION FROM SYSTIMESTAMP) AS EXTRACT_TIMEZONE_REGION,
  33. EXTRACT(TIMEZONE_ABBR FROM SYSTIMESTAMP) AS EXTRACT_TIMEZONE_ABBR
  34. FROM dual;
  35.  
  36. --Example 7
  37. SELECT TO_YMINTERVAL('03-02'),
  38. EXTRACT(YEAR FROM TO_YMINTERVAL('03-02')) AS EXTRACT_YEAR,
  39. EXTRACT(MONTH FROM TO_YMINTERVAL('03-02')) AS EXTRACT_MONTH
  40. FROM dual;

Report this snippet  

You need to login to post a comment.