删除触发器中第 5 行出现 PL/SQL 1064 错误

发布于 2024-10-30 18:54:05 字数 403 浏览 0 评论 0原文

我正在尝试创建一个触发器来在删除所有文章内容后删除文章。我在第 5 行收到 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 ;

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 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 ;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罪歌 2024-11-06 18:54:06

由于 PL/SQL 的语法无效,这里存在一些问题:

  1. 标识符要么是无分隔的,要么是使用 " 分隔的,而不是`

  2. declare 必须在 begin

    之前

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

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

  5. “分隔符”语句有什么用?只需用 ;

    结束触发器定义,

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 ;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文