2011-04-06 63 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. 與 「分隔符」 的語句是什麼?只需結束觸發定義;