create or replace trigger addTheme
after insert or delete on T_Article for each row
begin
if inserting then
update T_user set themeCount=themeCount+1 where id=:NEW.userId;--为该用户的主题数加一
update T_ForumStatistic set themeCount=themeCount+1; --论坛统计表主题数加一
else if deleting then
update T_user set themeCount=themeCount-1 where id=:OLD.userId;--为该用户的主题数减一
update T_ForumStatistic set themeCount=themeCount-1; --论坛统计表主题数减一
delete from T_reply where article_id=:old.id
end if;
end if;
end;SQL> show errors;
TRIGGER ADDTHEME 出现错误:LINE/COL ERROR
-------- -----------------------------------------------------------------
8/3 PL/SQL: SQL Statement ignored
9/7 PL/SQL: ORA-00933: SQL 命令未正确结束
11/4 PLS-00103: 出现符号 ";"在需要下列之一时:
if
plsql没else if
是:elsif
after insert or delete on T_Article for each row
begin
if inserting then
update T_user set themeCount=themeCount+1 where id=:new.userId;
update T_ForumStatistic set themeCount=themeCount+1;
elseif deleting then
update T_user set themeCount=themeCount-1 where id=:old.userId;
update T_ForumStatistic set themeCount=themeCount-1;
delete from T_reply where article_id=:old.id;
endif;
endif;
end;SQL> show errors;
TRIGGER ADDTHEME 出现错误:LINE/COL ERROR
-------- -----------------------------------------------------------------
5/9 PLS-00103: 出现符号 "DELETING"在需要下列之一时:
:= . ( @ % ;11/4 PLS-00103: 出现符号 ";"在需要下列之一时:
if
改过来试试,看清楚
create or replace trigger addTheme
after insert or delete on T_Article for each row
begin
if inserting then
update T_user set themeCount=themeCount+1 where id=:NEW.userId;--为该用户的主题数加一
update T_ForumStatistic set themeCount=themeCount+1; --论坛统计表主题数加一
--else if deleting then
elsif deleting then
update T_user set themeCount=themeCount-1 where id=:OLD.userId;--为该用户的主题数减一
update T_ForumStatistic set themeCount=themeCount-1; --论坛统计表主题数减一
delete from T_reply where article_id=:old.id
--end if;
end if;
end;