3

This is my code to search database entries with pattern as a value in parameter PLACE1,

DROP PROCEDURE `casetwosplit`;

CREATE DEFINER=`root`@`localhost` PROCEDURE `case` (IN `PLACE1` LONGTEXT)
       NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER 

select all PLACE,CITY,LATTITUDE,LONGITUDE 
from LOCATION 

where PLACE like @'%PLACE1%

On execution, I am getiing no result eventhough the values are present. When the value in the variable PLACE1 is provided explicitly, I am getting the result. But when the pattern in the like clause has the variable name it's not interpolating the variable value in the query.

1
  • Your question could be improved by formatting the code (sql in your case) as such as well as supplying some example data, that help understanding what is going on. Commented Jan 14, 2016 at 11:46

1 Answer 1

4

MySQL will not automatically replace parameter names within the string so you are always looking for a place name containing the string "PLACE1". What you need to do is add the wildcard characters to the parameter :

select all PLACE,CITY,LATTITUDE,LONGITUDE from LOCATION     
where PLACE like CONCAT('%', PLACE1, '%')
Sign up to request clarification or add additional context in comments.

2 Comments

Thank You, I got what i needed.
If you mean that I answered your question then you can mark it as a correct answer - that will help anybody else searching with a similar problem.

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.