情况1:
p_start_date = 13.Apr.2012 13:00
p_end_date = 13.Apr.2012 15:00
working_hours = 0
// in this Situation working_hours should be 2
情况2:
p_start_date = 13.Apr.2012 13:00
p_end_date = 14.Apr.2012 15:00
working_hours = 24
// in this Situation working_hours should be 26
当我使用 and 运行它时SQLDevelopper
,Situation 1
正确返回Situation 2
值。working_hours
但我将此程序称为Before Insert Update Trigger
在我的顶点应用程序中使用。当我提交表格形式时Situation 1
,值为working_hours
is 0
,当我提交表格形式时Situation 2
,值为working_hours
is 24
。
根据Situation 1
和Situation 2
,两个日期之间的差异分配给working_hours。但我需要的是两次之间的差异。
我怎么能那样做?
我的计算程序working_hours
是,
PROCEDURE get_labour_cost_data(
p_employee_id IN NUMBER,
p_start_date IN VARCHAR2,
p_end_date IN VARCHAR2,
hours_normal_rate OUT NUMBER,
working_hours OUT NUMBER,
total_cost OUT NUMBER)
AS
v_employee_rate NUMBER;
BEGIN
if p_employee_id is null then
hours_normal_rate := 0;
working_hours := 0;
total_cost := 0;
elsif p_employee_id is not null then
-- Get hourse_noraml from employee
select HOURLY_SALARY into hours_normal_rate from Employee
where EMPLOYEE_ID = p_employee_id;
-- Get working hours
working_hours := 24 * (to_date(p_end_date, 'dd.mm.rr hh24:mi') - to_date(p_start_date, 'dd.mm.rr hh24:mi'));
-- Get Total cost
total_cost := nvl(hours_normal_rate,0) * nvl(working_hours,0);
end if;
END;
触发器是,
create or replace
TRIGGER LABOUR_COST_BIU_TRI
BEFORE INSERT OR UPDATE ON LABOUR_COST
FOR EACH ROW
DECLARE
v_hours_normal NUMBER;
v_working_hours NUMBER;
v_total_cost NUMBER;
BEGIN
util.get_labour_cost_data(
p_employee_id => :NEW.EMPLOYEE_ID,
p_start_date => :NEW.START_DATE_TIME,
p_end_date => :NEW.END_DATE_TIME,
hours_normal_rate => v_hours_normal,
working_hours => v_working_hours,
total_cost => v_total_cost
);
select v_hours_normal, v_working_hours, v_total_cost into :NEW.HOURS_NOMAL, :NEW.HOURS_OT, :NEW.TOTAL_COST
from dual;
END;