开发者

PL/SQL 1064 error at line 5 in delete trigger

开发者 https://www.devze.com 2023-02-22 06:35 出处:网络
I am trying to create a trigger to delete articles after it deletes of all of its article contents. I am getting a 1064 error at line 5.

I am trying to create a trigger to delete articles after it deletes of all of its article contents. I am getting a 1064 error at line 5.

Here is the PL/SQL I have written:

delimiter |

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

delimiter ;


There's a few problems there, due to invalid syntax for PL/SQL:

  1. identifiers are either undelimited or delimited using ", not `

  2. declare must come before begin

  3. set is not a valid keyword. To get the count, use INTO, e.g. SELECT COUNT(*) INTO x FROM ...

  4. The DELETE statement refers to old.id, this should be :old.id

  5. What's with the "delimiter" statements? Just end the trigger definition with ;

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号