sql - Trigger compilation error -
i need in creating trigger.
create or replace trigger trigger_one before insert on funtom_timesheet each row declare v_id number; v_hours number; begin select max(timesheet_id)+1 v_id funtom_timesheet :new.timesheet_id :=v_id; select grade_hours v_hours funtom_grade join funtom_employee on emp_grade = grade_id empid = :new.timesheet_emp; if v_hours >:new.timesheet_hours else :new.timesheet_overtime := :new.timesheet_hours-v_hours :new.timesheet_hours:= v_hours; end if; end; /
please tell me part of code wrong work on it, thanks
you have many syntax errors - missing ;
, then
. there can't if
else
part , without expression on it.
create or replace trigger trigger_one before insert on funtom_timesheet each row declare v_id number; v_hours number; begin select max(timesheet_id) + 1 v_id funtom_timesheet; :new.timesheet_id := v_id; select grade_hours v_hours funtom_grade join funtom_employee on emp_grade = grade_id empid = :new.timesheet_emp; if v_hours > :new.timesheet_hours null; else :new.timesheet_overtime := :new.timesheet_hours - v_hours; :new.timesheet_hours := v_hours; end if; end; /
also better use sequences instead of:
select max(timesheet_id) + 1 v_id funtom_timesheet; :new.timesheet_id := v_id;
when selecting form same table inserting, can mutating trigger error (http://www.dba-oracle.com/t_avoiding_mutating_table_error.htm)
Comments
Post a Comment