13

以下是我的代码:

     DELIMITER $$

     CREATE DEFINER=`root`@`localhost` PROCEDURE `employee_with_asset`(IN name     VARCHAR(250))
     BEGIN
     SELECT a.Asset_code,a.name as name1,a.type,a.description,`purchase date`,
    `amc availability`,`amc renewal`,`employee Id`,b.Name FROM `asset_details` a,
     employee b WHERE  b.Name LIKE '%' + @name + '%' and a.`assigned to`=b.`employee Id`;
     END

它在 LIKE 附近显示错误。如何解决它。

4

3 回答 3

40

mysql中的连接是使用完成的CONCAT()

LIKE CONCAT('%', @name , '%')

完整声明

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `employee_with_asset`
(
    IN _name     VARCHAR(250)
)
BEGIN
    SELECT  a.Asset_code,
            a.name as name1,
            a.type,
            a.description,
            `purchase date`,
            `amc availability`,
            `amc renewal`,
            `employee Id`,
            b.Name 
    FROM    `asset_details` a
            INNER JOIN employee b 
                ON a.`assigned to` = b.`employee Id`
    WHERE   b.Name LIKE CONCAT('%', _name , '%');
END $$
DELIMITER ;
于 2013-04-09T07:57:04.103 回答
3

John Woo 的答案是正确的,但是如果您不使用 utf8_general_ci 集合,则必须在 WHERE 子句之后(如果您有多个条件,则在每个条件之后)将集合与您比较的列的集合相同

... WHERE name LIKE CONCAT('%', @name , '%') COLLATE utf8_unicode_ci

或多个条件

... WHERE name LIKE CONCAT('%', @name , '%') COLLATE utf8_unicode_ci
OR job LIKE CONCAT('%', @name , '%') COLLATE utf8_unicode_ci ...
于 2016-05-26T08:00:31.897 回答
0

PHP:

$keyword = $_POST['keyword'];
$response = "call user_search('%$keyword%');";

mysql:

....where user.name like @keyword;
于 2019-10-06T12:54:10.673 回答