当表格时间表获得批准(Timesheet_approved *为非空)时,应触发一个触发器,该触发器将计算到期的标准工时(Payroll_standard *)和任何加班的到期付款(Payroll_overtime * =标准小时数X 1.5)工资单上的前一周。
它还应该计算养老金缴款(Payroll_pension * =标准的10%+随着时间的推移)到期,然后更新工资表(计算出下一个工资单ID)
请注意*用于指出表属性的名称。正在使用/受影响的表是funtom_Timesheet和funtom_Payroll
到目前为止,我有以下代码。但是,我不断遇到错误的变量绑定错误:
LINE/COL ERROR
-------- -------------------------------------------------------------
32/3 PL/SQL: SQL Statement ignored
33/3 PL/SQL: ORA-01747: invalid user.table.column, table.column, or column specification
33/3 PLS-00049: bad bind variable 'NEW.PAYROLL_STANDARD'
34/3 PLS-00049: bad bind variable 'NEW.PAYROLL_OVERTIME'
35/3 PLS-00049: bad bind variable 'NEW.PAYROLL_PENSION'
41/1 PLS-00049: bad bind variable 'NEW.PAYROLL_ID'
SQL>
这是触发代码
CREATE OR REPLACE TRIGGER trg_PAYROLLCALC
After UPDATE
on funtom_Timesheet FOR EACH ROW
Declare
V_TimesheetHRS number;
V_GRADEHRS number;
V_TimesheetOT number;
v_OTGRADEHRS number;
v_payrollID number;
BEGIN
SELECT Grade_rate into V_GRADEHRS
FROM Grade join Employee on (Emp_grade = grade_id)
where emp_ID = Timesheet_emp
;
SELECT Timesheet_hours into V_TimesheetHRS
From Funtom_timesheet join Funtom_employee on (emp_ID = Timesheet_emp)
where emp_ID = Timesheet_emp
;
Select Timesheet_OT into V_TimesheetOT
From Timesheet join Employee on (emp_ID = Timesheet_emp)
where emp_ID = Timesheet_emp
;
select Sum(Grade_rate * 1.5) into v_OTGRADEHRS
from Grade join Employee on (Emp_grade = grade_id)
where emp_ID = Timesheet_emp
;
IF Timesheet_approved IS NOT NULL then
Update funtom_Payroll set
:new.Payroll_standard := V_GRADEHRS * V_TimesheetHRS;
:new.Payroll_overtime := v_OTGRADEHRS * V_TimesheetOT;
:new.Payroll_pension := ((V_GRADEHRS * V_TimesheetHRS)+(v_OTGRADEHRS * V_TimesheetOT));
END IF;
Select MAX(Payroll_id)+1 into v_payrollID
from Payroll;
:new.Payroll_id := v_payrollID;
END;
/
答案 0 :(得分:0)
错误是因为:new.<field_name>
是对funtom_Timesheet
中新行的可读引用,其行正在更新,导致触发此触发器。您的更新funtom_Payroll
命令需要您引用funtom_Payroll
位置的:new
表中的字段名称。您可以在:new
之后的此更新语句中引用:old
和:=
,但可能不是之前。如果你解释触发器应该做什么,我可以帮助修复触发器代码。