0

我正在尝试创建一个触发器,该触发器将在每次创建新记录时检查导师是否在特定周累积了 15 小时的辅导。表中的每条记录等于一个小时。特定导师的 15 条记录意味着 15 小时。我可以让它计算导师的所有记录,但它应该根据插入函数插入的日期计算一周内的记录。

Create or replace Trigger Tutor_15hr_Rule
Before Insert on Meeting
For each row
Declare
HoursWorked binary_integer;
begin
select count(TutID)
into HoursWorked
from Meeting
where TutID = :new.TutID AND MeetDate Next_Day (:new.MeetDate, 'Saturday');
DBMS_OUTPUT.PUT_LINE(HoursWorked);
if (HoursWorked + 1) > 15 then
Raise_application_Error(-20002, 'exceeded no of hours');
end if;
end;
/
show error;

预先感谢任何可以阐明的人。

4

2 回答 2

0

您可以将 to_char 与各种格式模型一起使用,将日期转换为年和周以及许多其他选项。

SELECT to_char(CURRENT_DATE,'YYYY IW') FROM DUAL

要更改一周的开始,您可以在转换前添加天数:

SELECT to_char(CURRENT_DATE + INTERVAL '2' DAY,'YYYY IW') FROM DUAL
于 2013-04-26T00:54:53.810 回答
0

以为我会分享最终代码。完美运行!!!(谢谢布赖恩!)

Create or replace Trigger Tutor_15hr_Rule
Before Insert on Meeting
For each row
Declare
HoursWorked binary_integer;
begin
select count(TutID)
into HoursWorked
from Meeting
where TutID = :new.TutID AND WorkWeek = (Select to_char(:new.MeetDate, 'YYYY IW') From Dual);
DBMS_OUTPUT.PUT_LINE(HoursWorked);
if (HoursWorked + 1) > 15 then
Raise_application_Error(-20002, 'exceeded no of hours');
end if;
end;
/
show error;
于 2013-04-29T23:35:01.823 回答