在MySQL中使用形如做模糊查询时提示错误You have an error in your SQL syntax;check the manual……-综合交流区论坛-低代码平台-本牛千智|专注WorkFine

在MySQL中使用形如做模糊查询时提示错误You have an error in your SQL syntax;check the manual……

直通车

charindex(短字段,长字段)>0

问题描述

使用形如模糊查询时,出现如下错误提示,如何解决?

You have an error in your SQL syntax;check the manual that comresponds to your MySQL server version for the right syntax to use near ‘
“+%LIMIT 1 OFFSET O’at line 3

解决方法1

形如是like关键字,在Mysql中不能像sqlserver一样用加号拼接字符串,要用 concat 函数进行拼接(具体使用如下图)。

-- 模糊匹配
本报表.[表].[字段] like concat('%', '关键字', '%')

-- 左匹配
本报表.[表].[字段] like concat('关键字', '%')

-- 右匹配
本报表.[表].[字段] like concat('%', '关键字')

解决办法2

MySQL中换用模糊查询函数charindex(短字段,长字段)

用法

  • charindex(短字段,长字段)>0 匹配上
  • charindex(短字段,长字段)=0 匹配
charindex(短字段,长字段)>0

在不考虑被查找字符在长字符中位置的情况下
此函数比形如效率要高

扩展学习

资料来源

请登录后发表评论

    请登录后查看回复内容