Converting a MySQL query, to a routine which takes parameter
I'm using VSC++ and MySQL ver.5.2.25 database, I've tested a query In MySQL that is like this:
select Name from test.virus where Name LIKE 'b' '%' ORDER BY Name;
It works well and return all Names that starts with 'b',I want to use a routine instead of this query, so that I can call the routine from my program. I've tried this:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `StartWith`(NewName VarChar(20))
BEGIN
select NameVirus from test.virus
where NameVirus LIKE "'+NewName+' '%'" ORDER BY NameVirus;
END
When I Call the routine in MySQL there is no error, but the result is an empty table, I guess that the problem is with type of arg开发者_如何学运维ument, Which type should be the "NewName" parameter?
Advanced thanks for any replyYour like condition in the example query is flawed. It should be 'b%'
.
The procedure where clause might need to look like this:
where NameVirus LIKE CONCAT(NewName,'%') order by NameVirus
精彩评论