简体   繁体   中英

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.

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:

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:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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