Plsql pl/sql中的触发器抛出错误

Plsql pl/sql中的触发器抛出错误,plsql,oracle11g,triggers,Plsql,Oracle11g,Triggers,我需要做的是,我想创建一个触发器,如果程序员的两个熟练程度相等,它会引发一个错误。请告诉我我犯了哪些错误 SQL> get f:/sqlprog/trigger_3; 1 create or replace trigger t2 before insert or update on programmer for each row 2 declare 3 cursor c1 is select prof1, prof2 from programmer;

我需要做的是,我想创建一个触发器,如果程序员的两个熟练程度相等,它会引发一个错误。请告诉我我犯了哪些错误

SQL> get f:/sqlprog/trigger_3;
  1  create or replace trigger t2 before insert or update on programmer for          each
 row
  2  declare
  3  cursor c1 is select prof1, prof2 from programmer;
  4  begin
  5  for r1 in c1 loop
  6  if r1.pname=:new.pname then
  7  if :new.prof1=: new.prof2 then
  8  raise_application_error(-20091,'prof1 and prof2 should not be same');
  9  end if;
  10  end if;
   11  end loop;
  12* end;
 SQL> /
警告:使用编译错误创建触发器

 SQL> show errors
 Errors for TRIGGER T2:

 LINE/COL ERROR
 -------- -----------------------------------------------------------------
 4/1      PLS-00103: Encountered the symbol "FOR" when expecting one of the
          following:
          constant exception <an identifier>
          <a double-quoted delimited-identifier> table long double ref
          char time timestamp interval date binary national character
          nchar

 6/15     PLS-00103: Encountered the symbol ":" when expecting one of the
          following:
          ( - + all case mod new null <an identifier>
          <a double-quoted delimited-identifier> <a bind variable>

 LINE/COL ERROR
 -------- -----------------------------------------------------------------
         continue any avg count current max min prior some sql stddev
         sum variance execute forall merge time timestamp interval
         date <a string literal with character set specification>
         <a number> <a single-quoted SQL string> pipe
         <an alternatively-quoted string literal with character set
         specification>
         <an alternative
我不知道我为什么要买它们,请帮帮我


提前谢谢。

去掉光标,丢失循环,去掉第一个
if
语句。只有最里面的
if
语句才有意义

create or replace trigger t2 
  before insert or update on programmer 
  for each row
begin
  if :new.prof1 = :new.prof2 
  then
   raise_application_error(-20091,'prof1 and prof2 should not be same');
  end if;
end;

在行级触发器中,通常无法查询定义触发器的表。您只能根据
:new
:old
伪记录中的数据做出决策。

您想实现什么?我的猜测是,您需要的是
检查
约束,而不是触发器。如果你想变得效率低下,想有一个触发器而不是一个约束,我猜你只想检查
If:new.prof1=:new.prof2
,然后去掉循环和第一个If语句。先生,我是新手,学习速度很慢,你能更准确地告诉我应该做什么吗?首先,准确地解释你想要实现的目标。我试着根据我认为你认为你的代码会做什么来猜测。但我的猜测完全有可能是错的。你为什么用扳机?为什么表中有两列而不是一对多映射表?每个程序员真的有两种能力吗?没有人有1或3?正如你所说的,可以使用检查约束,但我们的长官告诉我们只能使用触发器,即使我们可以按照你说的做。他这样说是为了练习。程序员可能有很多专长,但他(我们的先生)最后只给了我们两个专栏,他提出了这个问题让我们去解决。我试图做的是当任何插入记录的两列在prof1和prof2列中具有相同的值时引发错误。请看一下这个问题,先生,我已经编辑了一些。这是我在stackoverflow的第一个问题,所以请容忍我的错误。请给我你的gmail id,先生。如果有任何疑问,我会直接邮寄给你。如果你对此感到满意,我会告诉你。先生,请告诉我关于这个问题的任何好的参考资料
create or replace trigger t2 
  before insert or update on programmer 
  for each row
begin
  if :new.prof1 = :new.prof2 
  then
   raise_application_error(-20091,'prof1 and prof2 should not be same');
  end if;
end;