简体   繁体   English

我的sql IN()函数或FIND_IN_SET函数允许的最大逗号分隔字符串

[英]The max comma separated string allowed in my sql IN() Function or FIND_IN_SET Function

I been working on a project in which i have to find the mobile numbers exists in database table. 我一直在一个项目中,我必须找到数据库表中存在的手机号码。 The user is supposed to upload a list of mobile numbers which can go to the thousands of mobile numbers. 用户应该上传一个手机号码列表,该列表可以进入数千个手机号码。 so my main concern is that how long comma separated string of mobile numbers will allow to use in FIND_IN_SET() function of my sql. 因此,我主要担心的是,用逗号分隔的移动电话字符串可以在SQL的FIND_IN_SET()函数中使用多长时间。

Actually i don't want to store those numbers i just want to find that if any of number from uploaded list exists in table.so my query would be somthing like this: 其实我不想存储这些数字,我只是想发现如果table.so中存在上载列表中的任何数字,那么我的查询就是这样的:

SELECT * FROM table WHERE mobile IN('uploaded comma saperated string of numbers')

OR 要么

SELECT * FROM table WHERE FIND_IN_SET (mobile,'uploaded comma saperated string of numbers')

I would say the workaround here is to not use FIND_IN_SET at all, but rather use something like this: 我会说这里的解决方法是根本不使用FIND_IN_SET ,而是使用类似这样的方法:

WHERE number IN (num1, num2, ..., numN)

In other words, phrase your query by searching each record's phone number against a list of user inputs. 换句话说,通过在用户输入列表中搜索每个记录的电话号码来表达您的查询短语。 The number of terms which can appear inside an IN clause is limited only by the max_allowed_packet , and you probably would not be exceeding this under normal circumstances. IN子句中可以出现的术语数仅受max_allowed_packet限制,在正常情况下,您可能不会超过此数目。

I would suggest that instead of inserting mobile numbers as comma separated, insert them as single mobile number in single row. 我建议不要以逗号分隔插入手机号码,而应将它们作为单个手机号码插入单行。 If you do so, it would be very easy to do search and delete operation. 如果这样做,将非常容易执行搜索和删除操作。

Just upload list of mobile numbers with comma separated and then insert them with insert_bacth() function. 只需上传用逗号分隔的手机号码列表,然后使用insert_bacth()函数将其插入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM