问题描述
我只是调试旧版代码,但发现其中有一个奇怪的部分.有人知道吗,MYSQL字符串中的以下含义是什么?
I just debugging a legacy code and I found a strange part in it. Does anybody has an idea, what does the following mean in the MYSQL string?
full_name LIKE '%%{fullname}%%'
推荐答案
正如Mihir Dave的注释链接所指向的答案一样,如果传递%%
而不是%
,则SQL不会有任何区别.由于单个%
匹配零个或多个字符,因此%%
中的每个元字符也将匹配零个或多个,并且最终同一字符串将以一种或另一种方式匹配.
As in the answer Mihir Dave's comment links to, there's no difference to SQL if you pass %%
instead of %
. Since a single %
matches zero or more characters, then each of the metacharacters in %%
would also match zero or more, and ultimately the same string would match one way or another.
但是我想您的遗留代码是Python 2.6之前的版本,它使用%
作为字符串格式的元字符,并且您必须像%%
一样将其加倍以获取单个文字%
字符.
But I'd guess your legacy code is pre-Python 2.6 that uses %
as a metacharacter in string formatting, and you have to double it like %%
to get a single literal %
character.
另请参阅:
- 如何在Python中有选择地转义百分比(%)字符串?
- https://docs.python.org/2.6/library/stdtypes.html#string-formatting-operations
- How can I selectively escape percent (%) in Python strings?
- https://docs.python.org/2.6/library/stdtypes.html#string-formatting-operations
这篇关于mysql LIKE占两倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!