Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

When I create the stored procedure without parameter it works as expected, but when I create it with parameter it doesn't return any row.

DELIMITER //

CREATE PROCEDURE search()
BEGIN 
SELECT * FROM locality WHERE (LOWER( REPLACE(  `locality_area` ,  ' ',  '' ) ) REGEXP ('^.* GS Road.*$')) UNION ALL SELECT * FROM locality WHERE (`locality_area` REGEXP ('^.* GS Road.*$'));

END//

The above procedure returns the rows.

But this doesn't return any value

DELIMITER //

CREATE PROCEDURE search(IN **qry** varchar(100))
BEGIN 
SELECT * FROM locality WHERE (LOWER( REPLACE(  `locality_area` ,  ' ',  '' ) ) REGEXP ('^.* ***qry**.*$')) UNION ALL SELECT * FROM locality WHERE (`locality_area` REGEXP ('^.* ***qry**.*$'));

END//
share|improve this question

1 Answer 1

up vote 1 down vote accepted

That's because you're looking for the string 'qry' instead of the value held by the parameter qry.

Replace:

REGEXP ('^.* qry.$')) 

With

REGEXP CONCAT('^.* ',qry, '.$')) 
share|improve this answer
    
Thanks...its working –  user92961 Jun 4 '13 at 12:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.