我有两个表。表A像创建一个处理两个表的触发器
Name color
a1 red
a2 yellow
a3 black
a4 blue
表B就像
Name minutes action
b1 10 jump
b2 20 run
b3 40 dance
我创建一个触发器表B中插入行,如果动作是B.存在然后我打印新添加的信息。另外,如果新加入的人的颜色是红色,我会算表B中有更多/更少分钟多少人的代码是一样
create or replace trigger TR_insert_count
Before INSERT On B
For each row
DECLARE
l_act integer;
l_less integer;
l_more integer;
l_equal integer;
Begin
select count(1) into l_act
From B
Where Action=:new.Action;
select count(*)
into l_less
From B
Where Action=:new.Action and MINUTES > :new.minutes;
select count(*)
into l_more
From B
Where Action=:new.Action and MINUTES < :new.minutes;
select count(*)
into l_equal
From B
Where Action=:new.Action and MINUTES = :new.minutes;
if(l_act>0) then
DBMS_OUTPUT.PUT_LINE ('There is duplicate.');
DBMS_OUTPUT.PUT_LINE ('The new input info is with name ' || :new.Name || ' with
activity ' || :new.action ||' for ' ||:new.minutes || ' minutes.');
if(:new.name in (select Name From A where color='red')) then
DBMS_OUTPUT.PUT_LINE('There are '||l_more ||'people having more minutes.');
DBMS_OUTPUT.PUT_LINE('There are '||l_less ||'people having less minutes.');
DBMS_OUTPUT.PUT_LINE('There are '||l_equal ||'people having the same minutes.');
end if;
end if;
end
它被编译,但插排时,报告错误说触发无效。我想知道是因为我在这里有行级别或表级触发器,请问该怎么办?
谢谢,修正了,但还是想着如何解决它,也许把它分成两个触发器。 – 2014-11-24 15:44:40
2触发器不会有帮助 - 您需要按照文章中的描述使用3。另一种选择是创建存储过程,将数据插入'B'并打印所需的信息。然后,您可以撤销除存储过程之外的任何人的插入权限。注意:你的4个选项可以用一个替换。 – a1ex07 2014-11-24 15:58:05