0

我在将表 1 中的值与字符串进行比较时遇到了麻烦这是我尝试过的..

DELIMITER $$
DROP TRIGGER IF EXISTS comment_trigger$$
CREATE TRIGGER  comment_trigger AFTER INSERT ON post_comments
FOR EACH ROW
DECLARE 
@var_post_id varchar(20);
BEGIN
IF (NEW.post_id LIKE 'rmdid%') THEN
SET @var_post_id=SELECT post_id FROM recommendations WHERE recommendation_id=NEW.post_id;
IF(@var_post_id LIKE 'recid%') THEN
UPDATE cooking_category SET last_activity=NEW.comment_time WHERE post_id=NEW.post_id;
END IF;
END IF;
END$$
DELIMITER ;

有人可以帮我解决这个问题吗?

4

1 回答 1

0

您可以直接在select语句中分配变量:

SELECT @var_post_id = post_id
FROM recommendations
WHERE recommendation_id=NEW.post_id;

select这是首选,但如果您在语句周围加上括号,您的语法也可以使用:

SET @var_post_id=(SELECT post_id FROM recommendations WHERE recommendation_id=NEW.post_id);
于 2013-02-15T18:06:03.347 回答