简体   繁体   中英

mysql stored function parameter syntax error

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.

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

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;;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM