0

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.

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I had a terrible error with that trigger, I just need to evaluate the phone with the regexp. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.