假设您使用的是默认HR
模式,则触发器编译得很好。
C:\Users\jcave>sqlplus hr/hr
SQL*Plus: Release 11.2.0.1.0 Production on Mon Mar 18 16:55:42 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create or replace trigger check_dept
2 BEFORE INSERT ON employees
3 FOR EACH ROW
4 DECLARE
5 c number(1);
6 BEGIN
7 select count(*) INTO c from departments where departments.department_id=:new.department_id;
8
9 IF c = 0 THEN
10 insert into departments(department_id,department_name) values (:new.department_id,'others');
11 END IF;
12
13 END;
14 /
Trigger created.
SQL> ed
Wrote file afiedt.buf
1 insert into employees( employee_id, first_name, last_name, email, hire_date, job_id, department_id)
2* values( -1, 'Justin', 'Cave', 'foo@bar.com', sysdate, 'AC_ACCOUNT', 10 )
SQL> /
1 row created.
如果您的触发器无效,则您发布的触发器与您实际编译的触发器有一些不同,或者您没有使用默认HR
模式,在这种情况下,您需要告诉我们您的表是什么样的。