Oracle取年和月

xypincle發表於2017-02-19

  1. CREATE OR REPLACE FUNCTION comm.get_year(start_date DATE,end_date DATE)
  2. RETURN NUMBER
  3. IS
  4. service_interval INTERVAL YEAR TO MONTH;
  5. years_of_service NUMBER;
  6. BEGIN
  7.   service_interval := (end_date - start_date) YEAR TO MONTH;
  8.   years_of_service := EXTRACT(YEAR FROM service_interval);
  9.   RETURN years_of_service ;
  10. END;
  11.   
  12. CREATE OR REPLACE FUNCTION comm.get_month(start_date DATE,end_date DATE)
  13. RETURN NUMBER
  14. IS
  15. service_interval INTERVAL YEAR TO MONTH;
  16. months_of_service NUMBER;
  17. BEGIN
  18.   service_interval := (end_date - start_date) YEAR TO MONTH;
  19.   months_of_service := EXTRACT(MONTH FROM service_interval);
  20.   RETURN months_of_service ;
  21. END;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28878983/viewspace-2133885/,如需轉載,請註明出處,否則將追究法律責任。

相關文章