删除触发器中第 5 行出现 PL/SQL 1064 错误
我正在尝试创建一个触发器来在删除所有文章内容后删除文章。我在第 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 PL/SQL 的语法无效,这里存在一些问题:
标识符要么是无分隔的,要么是使用 " 分隔的,而不是`
declare
必须在begin
之前
set
不是有效的关键字。要获取计数,请使用INTO
,例如SELECT COUNT(*) INTO x FROM ...
DELETE 语句引用
old.id,这应该是
:old.id
“分隔符”语句有什么用?只需用
;
结束触发器定义,
There's a few problems there, due to invalid syntax for PL/SQL:
identifiers are either undelimited or delimited using ", not `
declare
must come beforebegin
set
is not a valid keyword. To get the count, useINTO
, e.g.SELECT COUNT(*) INTO x FROM ...
The DELETE statement refers to
old.id
, this should be:old.id
What's with the "delimiter" statements? Just end the trigger definition with
;