MySQL触发问题

我得到了这个触发器,如果​​regexp返回一个值,我想评估手机并插入另一个表。我试过这个但没有成功。
delimiter //

create trigger companyA_phones after insert on customer

for each row

begin

   set @phone = (select new.phone from customer where new.phone regexp '^0416');

   if (@phone) then

      insert into company_A(new.id, @phone);

   end if;

end//
    
已邀请:
你没有完全清楚你遇到了什么麻烦,但我不认为你需要选择那样的.new值 - 因为它们已经可以使用了。尝试这样的事情:
CREATE TRIGGER companyA_phones
AFTER INSERT ON customer
FOR EACH ROW
BEGIN
  IF (new.phone REGEXP '^0416' AND new.id IS NOT NULL) THEN
    INSERT INTO company_A (customerid, phone)
         VALUES (new.id, new.phone);
  END IF;
END
对此触发器的需求确实表明您的底层架构设计未正确规范化,因此您可能也想要考虑这一点。     

要回复问题请先登录注册