使用子查询创建触发器

时间:2015-06-07 13:07:57

标签: oracle plsql triggers

我有桌面球员阵容。而且我想创建一个触发器,它不允许在一行中插入超过11个玩家。

表有3列。 Id,IdLineup,IdPlayer。

我的代码:

create or replace
trigger maximum_hracu before insert on sestava for each row

begin
if inserting then
  if (select count(*) from hraje where hraje.id_sestava = :new.id_sestava) <= 11 then
    insert into hraje values(seq_hraje.nextval,:new.id_sestava,1);  
  end if;
end if;
end;

1 个答案:

答案 0 :(得分:0)

在PL / SQL中,始终使用INTO子句来赋值。

您可以尝试使用以下(未测试):

Begin
select count(*)  INTO v_abc from hraje where hraje.id_sestava = :new.id_sestava
...
if (v_abc <= 11) Then
insert into hraje...
...
相关问题