duangou2028 2013-08-07 07:54
浏览 37
已采纳

喜欢不在存储过程中工作

I have written stored procedure using like operator, but i am getting error of mysql. Here is my query:

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

When i print the query i get the following result:

SELECT *  FROM `categorybanners` WHERE TIERCODES LIKE %t2_05% and SITEID=46 and  CATLEVEL='tire4'

The main cause of error missing single quotes from %t2_05%. Please let me know how to put single quotes, to make query look like this:

SELECT *  FROM `categorybanners` WHERE TIERCODES LIKE '%t2_05%' and SITEID=46 and  CATLEVEL='tire4'
  • 写回答

1条回答 默认 最新

  • douping4436 2013-08-07 07:57
    关注

    Just put the single quotes in front of the first % and after the last %:

    SET @SS = CONCAT("SELECT *  FROM `categorybanners` WHERE TIERCODES LIKE '%",pTier4,"%'"," and SITEID=",pSiteid," and CATLEVEL='tire4'");
    

    So that your statement becomes:

    SELECT * FROM categorybanners WHERE TIERCODES LIKE '%t2_05%' and SITEID=46 and CATLEVEL='tire4'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入