0

What is wrong with this syntax?

mysql 5.5, phpmyadmin 3.4

delimiter ;;
create procedure foo(a text, b int, c text)
begin
select * from table_a where attribute1 like %a% 
and attribute2 = b
and attribute3 like %c%
end
;;

phpmyadmin tells me wrong syntax at line 1, but it doesn't seem to work, no matter what.

1
  • @AndaIancu Same error, but the double semicolon worked before, i dont think thats the problem Commented Aug 30, 2013 at 13:51

2 Answers 2

2

In your case you don't even need to change DELIMITER and use BEGIN ... END block. Your procedure might look like

CREATE PROCEDURE foo(a TEXT, b INT, c TEXT)
SELECT * 
  FROM table_a 
 WHERE attribute1 LIKE CONCAT('%', a, '%')
   AND attribute2 = b
   AND attribute3 LIKE CONCAT('%', c, '%');

Here is SQLFiddle demo

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

1 Comment

This answer generates the LIKE clause with the parameters passed to the procedure, producing a string. Your original %a% was not a valid string.
0

Missing quotes.

delimiter ;;

create procedure foo(a text, b int, c text)
begin
  select * from table_a where attribute1 like concat('%', a,' %') 
  and attribute2 = b
  and attribute3 like concat('%', c,' %');
end;;

1 Comment

Wouldn't that mean that I'm looking for text similar to the letter 'a' and 'c'? I want to use parameters.

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.