Function, which is passed to two times and returns the working time.

Source: Internet
Author: User

Create or replace function fun_get_hour (starttime in varchar2, endtime in varchar2) return number
Is
N_day number; -- days separated
V_start_day varchar2 (10): = substr (starttime, 1, 10 );
V_end_day varchar2 (10): = substr (endtime, 1, 10 );
V_start_time varchar2 (10): = substr (starttime, 12 );
V_end_time varchar2 (10): = substr (endtime, 12 );
Up_time varchar2 (10): = '08: 30: 00 ';
Down_time varchar2 (10): = '17: 30: 00 ';
N_timer number;
N_minute number;
N_hours number;
N_second number;
Begin
Select to_date (v_end_day, 'yyyy-MM-DD ')-to_date (v_start_day, 'yyyy-MM-DD') into n_day from dual;
N_day: = n_day + 1;
If n_day = 1 and v_start_time <up_time and v_end_time <up_time then
Return 0;
End if;
For X in 1 .. n_day Loop
If x = 1 then
If v_start_time> down_time then
N_timer: = 0;
Else
If v_start_time <up_time then
V_start_time: = up_time;
End if;
If n_day = 1 and down_time> v_end_time then
Down_time: = v_end_time;
End if;
N_minute: = to_number (to_char (to_date (down_time, 'hh24: MI: ss'), 'mi ')-to_number (to_char (to_date (v_start_time, 'hh24: MI: ss'), 'mi '));
N_hours: = to_number (to_char (to_date (down_time, 'hh24: MI: ss'), 'hh24')-to_number (to_char (to_date (v_start_time, 'hh24: MI: SS '), 'hh24 '));
N_second: = to_number (to_char (to_date (down_time, 'hh24: MI: ss'), 'ss')-to_number (to_char (to_date (v_start_time, 'hh24: MI: ss'), 'ss '));
N_timer: = n_minute * 60 + n_hours * 60*60 + n_second; -- submission time
End if;
Elsif x = n_day then
If v_end_time <up_time then
N_timer: = n_timer + 0;
Else
If v_end_time> down_time then
V_end_time: = down_time;
End if;
N_minute: = to_number (to_char (to_date (v_end_time, 'hh24: MI: ss'), 'mi ')-to_number (to_char (to_date (up_time, 'hh24: MI: ss'), 'mi '));
N_hours: = to_number (to_char (to_date (v_end_time, 'hh24: MI: ss'), 'hh24')-to_number (to_char (to_date (up_time, 'hh24: MI: SS '), 'hh24 '));
N_second: = to_number (to_char (to_date (v_end_time, 'hh24: MI: ss'), 'ss')-to_number (to_char (to_date (up_time, 'hh24: MI: ss'), 'ss '));
N_timer: = n_timer + n_minute * 60 + n_hours * 60*60 + n_second;
End if;
Else
N_minute: = to_number (to_char (to_date (down_time, 'hh24: MI: ss'), 'mi ')-to_number (to_char (to_date (up_time, 'hh24: MI: ss'), 'mi '));
N_hours: = to_number (to_char (to_date (down_time, 'hh24: MI: ss'), 'hh24')-to_number (to_char (to_date (up_time, 'hh24: MI: SS '), 'hh24 '));
N_second: = to_number (to_char (to_date (down_time, 'hh24: MI: ss'), 'ss')-to_number (to_char (to_date (up_time, 'hh24: MI: ss'), 'ss '));
N_timer: = n_timer + n_minute * 60 + n_hours * 60*60 + n_second;
End if;
End loop;
Return n_timer;
End fun_get_hour;

Function, which is passed to two times and returns the working time.

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.