我已经使用 like 运算符编写了存储过程,但是我收到了 mysql 的错误。这是我的查询:
CREATE DEFINER=`ecp`@`localhost` PROCEDURE `sp_getTier4CatBanner`(pSiteid int,pTier4 varchar(100))
BEGIN
SET @SS = CONCAT("SELECT * FROM `categorybanners` WHERE TIERCODES LIKE %",pTier4,"%"," and SITEID=",pSiteid," and CATLEVEL='tire4'");
PREPARE STMT FROM @SS;
END
当我打印查询时,我得到以下结果:
SELECT * FROM `categorybanners` WHERE TIERCODES LIKE %t2_05% and SITEID=46 and CATLEVEL='tire4'
错误的主要原因是缺少单引号%t2_05%
。请让我知道如何加上单引号,使查询看起来像这样:
SELECT * FROM `categorybanners` WHERE TIERCODES LIKE '%t2_05%' and SITEID=46 and CATLEVEL='tire4'