1

I have this little simple trigger..

BEGIN

    DECLARE FILE_NAME VARCHAR(250);
    DECLARE FILE_REFR VARCHAR(500);


SET FILE_NAME = 'Foo';
SET FILE_REFR = 'Bar';

--- I'd like to execute the next statement, using variable FILE_REFR between %% in a LIKE clause:
SELECT COUNT(*) INTO @num_rows FROM referers WHERE filename = FILE_NAME AND ref NOT LIKE "%FILE_REFR%";

...
...
...

END

Unfortunately, the variable name is not being picked up as a variable.. but as a CHAR, I know there is something missing there.

Help is more than appreciated.. :)

0

2 Answers 2

2

Use the variable as:

CONCAT('%', FILE_REFR, '%');

So the complete select query is:

SELECT COUNT(*) INTO @num_rows FROM referers WHERE filename = FILE_NAME AND ref NOT LIKE  CONCAT('%', FILE_REFR, '%');

Thanks

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

Comments

1

Is this what you want?

SELECT COUNT(*) INTO @num_rows
FROM referers
WHERE filename = FILE_NAME AND
      ref NOT LIKE CONCAT('%', FILE_REFR, '%');

MySQL does not find variables inside string literals. Instead you have to use CONCAT() to piece the pattern together.

Comments

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.