非常感谢你的回答…… 在你的提示下,我建了一个instead of触发器,结果提示:插入数据时不能在表上创建instead of 触发器 然后我索性改为对视图创建触发器,编码发下:/*********用instead of 触发器解决*********/ ----1.创建emp表的视图 create or replace view v_emp as select * from emp;----2.对视图v_emp创建instead of 触发器 create or replace trigger tri_emp_ck_sal instead of insert on v_emp for each row declare sal_error exception; Thesal emp.sal%type; begin select :new.sal into thesal from dual; if thesal > 10000 or thesal < 800 then -----工资不符合要求,抛出异常 raise sal_error; else ----符合要求的数据,插入数据库 insert into v_emp values(:new.empno,:new.ename,:new.job,:new.mgr,:new.hiredate,:new.sal,:new.comm,:new.deptno); end if;
exception when sal_error then dbms_output.put_line('输入的工资不符合要求'); end tri_emp_ck_money;---测试 insert into v_emp values(7901,'史密斯','职员',7698,sysdate,15000,null,10); select * from emp结果顺利通过呵呵……问题解决了,我还学到了其他的知识点,非常感谢你们
两个触发器就合并成一个。好管理
delete from emp where exists(select 1 from tmp where rid = emp.rowid);
就是删除emp和tmp的rid=rowid相等的记录
非常感谢你的回答……
第二个问题我有点儿明白了
这两个触发器好像不能合并成一个,
我试过,执行插入语句时报错
好像是因为插入数据后,当前数据在触发器tri_check_sal中是锁定的,不能被删除,只有在另一个触发器tri_emp_del中对其进行删除
非常感谢你的回答……
在你的提示下,我建了一个instead of触发器,结果提示:插入数据时不能在表上创建instead of 触发器
然后我索性改为对视图创建触发器,编码发下:/*********用instead of 触发器解决*********/
----1.创建emp表的视图
create or replace view v_emp
as
select * from emp;----2.对视图v_emp创建instead of 触发器
create or replace trigger tri_emp_ck_sal
instead of insert on v_emp
for each row
declare
sal_error exception;
Thesal emp.sal%type;
begin
select :new.sal into thesal from dual;
if thesal > 10000 or thesal < 800 then
-----工资不符合要求,抛出异常
raise sal_error;
else
----符合要求的数据,插入数据库
insert into v_emp values(:new.empno,:new.ename,:new.job,:new.mgr,:new.hiredate,:new.sal,:new.comm,:new.deptno);
end if;
exception
when sal_error then
dbms_output.put_line('输入的工资不符合要求');
end tri_emp_ck_money;---测试
insert into v_emp values(7901,'史密斯','职员',7698,sysdate,15000,null,10);
select * from emp结果顺利通过呵呵……问题解决了,我还学到了其他的知识点,非常感谢你们