create or replace trigger trg_i_bdz_xlmc2003 
   after insert 
   on line_hour_xs2003
   for each row
declare 
   bdzmc varchar2(30);
   xlmc  varchar2(30);
begin 
   bdzmc := :new.bdzmc;
   xlmc := :new.xlmc;
  if (bdzmc!="" and xlmc!="")  then 
    begin 
     if (select count(*) from bdz_xlmc2003 where bdzmc=bdzmc and xlmc=xlmc)=0  then
     begin 
   insert into bdz_xlmc2003 values (bdzmc,xlmc) ;
     commit;
     exception when others then 
     rollback;
     dbms_output.put_line("Invalid inserted");
   end;
     end if;
    end;
   end if;
end;
该触发器运行时报错,if (select count(*) from bdz_xlmc2003 where bdzmc=bdzmc and xlmc=xlmc)=0  then...报在这个地方,好像没有什么错吧。
请高手指点~~~

解决方案 »

  1.   

    这个触发器你能编译通过?错误实在是太多了,语法的和逻辑的都有。触发器中不能有commit之类的,判断是否为空是用is null或is not null,不能有if(select ...)=0这样的写法,字符串使用单引号而不是双引号。
      

  2.   

    刚刚说错了,是编译不过,报错~~
    if (select ...)=0不能这样写,那应该怎么写呀?
      

  3.   

    先select into到一个变量,再判断变量。逻辑上的错误还有个就是变量名不能与字段同名。
      

  4.   

    OK~~谢谢bobfang~~
    按照你说的,已经改好啦,编译也通过啦~~
    结贴给分啦!