我想在测试表中获取该名称并将其拆分为"至"字和&在abc表中插入拆分的字符串。 触发器被触发,但是当插入数据进入测试时它会生成 "#1172 - 结果由多行组成" phpMyAdmin中的错误。 请帮我解决一下这个。
DROP TRIGGER IF EXISTS `split_after_insert`;
CREATE DEFINER=`root`@`localhost`
TRIGGER `split_after_insert` AFTER INSERT ON `test`
FOR EACH ROW
BEGIN
DECLARE vName varchar(50);
-- Find name of person performing the INSERT into table
SELECT SUBSTR(name,(POSITION("to" IN name)+4),20) FROM test INTO vName;
-- Insert record into abc table
INSERT INTO abc(a) VALUES (vName);
END
答案 0 :(得分:0)
DROP TRIGGER IF EXISTS `j`;
CREATE DEFINER=`root`@`localhost`
TRIGGER `j` AFTER INSERT ON `test`
FOR EACH ROW
BEGIN
DECLARE vName varchar(100);
DECLARE vtemp varchar(100);
select new.name into vtemp;
-- Find name of person performing the INSERT into table
SELECT SUBSTR(vtemp,(POSITION("to" IN vtemp)+3),20) INTO vName;
-- Insert record into abc table
INSERT INTO `abc`(`a`) VALUES (vName );
END