2011-04-06 58 views
1

我想创建一个触发器,删除删除其所有文章内容后的文章。我得到一个1064 error at line 5删除触发器中第5行的PL/SQL 1064错误

这里是PL/SQL我已经写:

delimiter | 

create trigger `cleanup_article` after delete on `article_content` 
for each row 
begin 
    declare x int; 
    set x = select count(*) as x from `article_content` where id = old.id; 
    if x = 0 then 
     delete from `article` where id=old.id; 
    end if; 
end | 

delimiter ; 

回答

1

有一些问题存在,由于对PL/SQL语法无效:

  1. 标识要么未分隔或分隔使用”不是'

  2. declare必须出现在begin

  3. set不是有效的关键字。要获得计数,请使用INTO,例如SELECT COUNT(*) INTO x FROM ...

  4. DELETE语句是指old.id,这应该是:old.id

  5. 与 “分隔符” 的语句是什么?只需结束触发定义;