MYSQL-无法更新存储函数/触发器中的表,因为它已被调用此存储函数/触发器的语句使用

ido*_*ido 2 mysql triggers

我不断收到此错误:“无法更新存储函数/触发器中的表‘wp_posts’,因为它已被调用此存储函数/触发器的语句使用”

当 Woocommerce 向WP_posts表中插入一条记录时,我希望触发器确定正在插入的新记录是否具有post_title (column) = 'scheduled_subscription_end_of_prepaid_term' (field data). 如果是这样,我希望触发器IDnew.post_content(新插入行中的列/数据)中提取一个。

提取 ID 后,我想更新 ID。该 ID 与新插入行的 ID 不同。

有人可以告诉我我做错了什么吗?

delimiter //
create TRIGGER DB.Cancel
before INSERT ON DB.wp_posts FOR EACH ROW

BEGIN

DECLARE updateid bigint;
Declare variable longtext;
declare variable2 longtext;

IF NEW.post_title = 'scheduled_subscription_end_of_prepaid_term' then

set updateid := NEW.id;
set variable := RIGHT(new.post_content, LOCATE(":", new.post_content));
set variable2 :=  LEFT(variable, LOCATE("2052", variable)-2);

update db.wp_posts
set post_status="wc-cancelled"
where id=variable2 and post_status='wc-processing';

end if;
END//
Run Code Online (Sandbox Code Playgroud)

Uue*_*rdo 7

如果您尝试在插入的行完全插入之前对其进行更改,则只需设置新值,而不需要运行更新。

如果您尝试更新与触发器相同的表中的一个或多个不同的行,这是不允许的。