像sql中的命令

发布于 2025-02-10 08:15:16 字数 335 浏览 1 评论 0原文

我尝试编写一个带有类似命令的查询以搜索特殊名称,但是我需要从用户那里获取值,我需要读取该值,但是我的SQL代码在“ kike”部分中存在问题,我该如何修复?

sql = '''SELECT Name FROM newtest WHERE Name LIKE = %s'''
val = (n)
myobj = mycurs.execute(sql , val)

有什么问题?

您在SQL语法中有错误;查看与您的MariadB服务器版本相对应的手册,以获取正确的语法,以接近1

在第1行中使用'=%s'

这是错误

I tried to write a query with Like command to search for special Name , but i need to get the value from User and i need to read the value but my sql code has problem with "LIKE" section , how can i fix it ?

sql = '''SELECT Name FROM newtest WHERE Name LIKE = %s'''
val = (n)
myobj = mycurs.execute(sql , val)

what's the problem ?

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '= %s' at line 1

this is the error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

删除→记忆 2025-02-17 08:15:16

删除“ =”符号。类似命令不使用它 - 请参见 https:///www.w3schools.com/sql/ssql/ sql_ref_like.asp 示例。

Remove the "=" sign. The LIKE command doesn't use that - see https://www.w3schools.com/sql/sql_ref_like.asp for an example.

携君以终年 2025-02-17 08:15:16

如果您需要搜索非外观匹配(即名称在列中的任何位置),则可以将查询更改为:

SELECT Name FROM newtest WHERE Name LIKE concat('%', %s, '%')

If you need to search for non-exact matches (i.e. the name is anywhere inside the column) you can change the query as:

SELECT Name FROM newtest WHERE Name LIKE concat('%', %s, '%')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文