创建 instead of 触发器遇到的问题
suxun 2008-06-14 05:09:13 我先创建了emp表
create table emp (emp_id number(5) primary key, emp_name varchar2(20),
emp_salary number(4));
将emp表的emp_id属性设置为关键字
然后创建dept表
create table dept (dept_id number(3),dept_name varchar2(20),emp_id number(5),
constraint fk_empid foreign key(emp_id) references emp(emp_id));
创建视图
create or replace view dept_emp as select system.emp.EMP_ID,
system.emp.EMP_NAME, system.dept.DEPT_NAME, system.emp.EMP_SALARY
from system.dept, system.emp where system.emp.EMP_ID = system.dept.EMP_ID;
创建instead of 触发器
create or replace trigger tr_instead_of_dept_emp
instead of insert on dept_emp
for each row
declare
v_temp int;
begin
select count(*) into v_temp from dept
where DEPT_ID = :new.DEPT_ID;
if v_temp = 0 then
insert into dept(DEPT_ID,DEPT_NAME,EMP_ID)
values(:new.DEPT_ID,:new.DEPT_NAME,:new.EMP_ID);
end if;
select count(*) into v_temp emp
where EMP_ID = :new.EMP_ID;
if v_temp = 0 then
insert into emp(EMP_ID,EMP_NAME,EMP_SALARY)
values(:new.EMP_ID,:new.EMP_NAME,EMP_SALARY);
end if;
end;
编译运行后出现:NEW.DEPT_ID赋值错误。
请问那个大侠知道问题出现在什么地方,请给予指教。谢谢。。。