Oracle datediff evaluate the date, Week, and month Functions

Source: Internet
Author: User

Oracle datediff evaluate the date, Week, and month Functions

Oracledatediff date week month create or replace function datediff (type in varchar2, startTime in varchar2, endTime in varchar2, v in varchar2) return number as v_result number; SQL _1 varchar2 (200 ); begin dbms_output.put_line ('1'); if (type = 'day') then SQL _1: = 'select' | v | '(TO_NUMBER (to_date (''' | startTime | ''', ''yyyy-MM-DD '') -to_date (''' | endTime | ''', ''yyyy-MM-DD '') from dual'; dbms_output.put_line ('1 '); elsif (type = 'month') then SQL _1: = 'select' | v | '(months_between (to_date (''' | startTime | ''', ''yyyy-MM-DD '')-to_date (''' | endTime | ''', ''yyyy-MM-DD'') from dual '; dbms_output.put_line ('1'); elsif (type = 'Week ') then dbms_output.put_line ('1'); SQL _1: = 'select' | v | '(TO_NUMBER (to_date (''' | startTime | ''', ''yyyy-MM-DD '') -to_date (''' | endTime | ''', ''yyyy-MM-DD '')/7) from dual'; end if; dbms_output.put_line (SQL _1 ); execute immediate SQL _1 into v_result; return (v_result); end; -- first EXECUTE the above function, so that you can write this function in Oracle. You can use this method: select datediff ('Week ', '2014-09-01', '2014-08-01 ', 'round') from dual; -- Description 'Week' indicates week, 'month' indicates month, 'day' indicates the day-two dates are passed in the middle-the fourth parameter: round the week or month with 'row', round up with 'ceil 'and round down with 'floor'

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.