im在以下表上尝试触发oracle sqlplus
SQL> create table Employees1727
2 (
3 emp_id number(4) primary key,
4 last_name varchar2(15),
5 first_name varchar2(15),
6 email varchar2(30),
7 phone_no varchar2(12),
8 hire_date date,
9 job_id varchar2(10),
10 salary number(10),
11 commission_pct number(2,2),
12 manager_id number(4) references Employees1727(emp_id),
13 dept_id number(3)
14 );
表已创建。
SQL>
SQL>
SQL> create table Departments1727
2 (
3 dept_id number(4),
4 dept_name varchar2(15),
5 manager_id number(4) references Employees1727(emp_id),
6 loc_id number(4)
7 );
表已创建。
SQL> create or replace trigger businesshr
2 before insert or update or delete on Employees1727
3 for each row
4 begin
5 if to_char(sysdate, 'hh24') >= '05' AND
6 to_char(sysdate, 'hh24') <= '18'
7 then
8 select * into
9 :new.emp_id,
10 :new.last_name,
11 :new.first_name,
12 :new.email,
13 :new.phone_no,
14 :new.hire_date,
15 :new.job_id,
16 :new.salary,
17 :new.commission_pct,
18 :new.manager_id,
19 :new.dept_id
20 from Employees1727 ;
21 else
22 raise_application_error (-20000, 'Employee info may not be modified at this time!') ;
23 end if;
24 end businesshr;
25 /
触发器已创建。
SQL> insert into Employees1727 values(1,'Patil','Pratik','Pratik@gmail.com',23994723, '12-FEB-2010',101,15000,0,1,2);
insert into Employees1727 values(1,'Patil','Pratik','Pratik@gmail.com',23994723, '12-FEB-2010',101,15000,0,1,2)
*
第1行出现错误:
ORA-01403:找不到数据
ORA-06512:位于“ SCOTT.BUSINESSHR”的第5行,
ORA-04088:执行触发器'SCOTT.BUSINESSHR'时发生错误
答案 0 :(得分:0)
在触发器中,您不应从正在操作触发器的表中进行选择,因为会出现mutating table
错误。在这种情况下,根本不需要选择,只需将其编写为:
create or replace trigger businesshr
before insert or update or delete on Employees1727
for each row
begin
if to_char(sysdate, 'hh24') < '05' or '18' < to_char(sysdate, 'hh24') then
raise_application_error (-20000, 'Employee info may not be modified at this time!') ;
end if;
end businesshr;