1

So im creating a procedure that accepts an argument namee and returns all users whose name is a substring of namee

    create procedure search_res(IN namee varchar(50))
    begin
    select * from usr where name like %namee%;
    end

But im getting the following error. #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%namee%; end' at line 3. What is the correct syntax?

3
  • Wouldn't you need to add quotations to '%namee%'? Commented Oct 11, 2014 at 14:15
  • adding quotes will match the word namee as such instead of the value inside namee. Commented Oct 11, 2014 at 14:20
  • Can you add sample data of usr table Commented Oct 11, 2014 at 15:07

1 Answer 1

2

Use CONCAT function

select * from usr where name like CONCAT('%',namee,'%');
Sign up to request clarification or add additional context in comments.

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.