开发者

MySQL trigger issue

I got this trigger, I want to evaluate the mobile phone and insert into another table if the regexp returns a value. I've tried with this but not success.

del开发者_如何学运维imiter //

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//


You don't make it entirely clear what trouble you are having, but I don't think you need to be selecting the .new values like that -- as they are already available to you. Try something like this:

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

The need for this trigger does seem to suggest that your underlying schema design is not correctly normalised, so you might want to think about that too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜