0

当我的一个表中发生插入时,我想转换一个字段。

检查和 ged 的​​ => 检查和 geds。

DELIMITER $$
CREATE TRIGGER `perma_limk_insertion` AFTER INSERT
ON `tbl_magazine_subscription`
FOR EACH ROW BEGIN

    DECLARE magazine_name VARCHAR(100); 
    DECLARE magazine_name_from_table VARCHAR(100); 
    DECLARE magazine_name_new VARCHAR(100); 
    SET @magazine_name_from_table := (SELECT MAGAZINE_NAME FROM tbl_magazine WHERE MAGAZINE_ID = NEW.magazine_id LIMIT 1);
    SET @magazine_name            := REPLACE(@magazine_name_from_table,'&','and');
    SET @magazine_name_new        := REPLACE(@magazine_name,"'",'');
    UPDATE tbl_magazine SET perma_link = @magazine_name_new WHERE MAGAZINE_ID = NEW.magazine_id;
END$$
 DELIMITER ;

但是使用上面的查询他们没有更新。如果我的查询有任何问题

如果有人知道这一点,请帮助我。

4

1 回答 1

0

试试这个,从任何地方删除“@”。当你想从表中选择一个值到一个变量中时使用INTO 。

    DELIMITER $$ 
        CREATE TRIGGER perma_limk_insertion AFTER INSERT ON tbl_magazine_subscription FOR EACH ROW BEGIN

            DECLARE magazine_name VARCHAR(100); 
            DECLARE magazine_name_from_table VARCHAR(100); 
            DECLARE magazine_name_new VARCHAR(100); 

  //changed from SET to INTO here
  SELECT MAGAZINE_NAME INTO magazine_name_from_table FROM tbl_magazine
  WHERE MAGAZINE_ID = NEW.magazine_id LIMIT 1;

            SET magazine_name            := REPLACE(magazine_name_from_table,'&','and');
            SET magazine_name_new        := REPLACE(magazine_name,"'",'');
            UPDATE tbl_magazine SET perma_link = magazine_name_new WHERE MAGAZINE_ID = NEW.magazine_id;
        END$$

     DELIMITER ;

要了解更多关于会话变量和局部变量的信息,请点击此处,

MySQL:@variable 与变量。有什么不同?

于 2013-08-27T13:57:46.443 回答