Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql string concatenation problem sharing

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces mysql string concatenation problem sharing, I hope you can supplement and update some knowledge, if you have other questions you need to know, you can continue to follow my updated article in the industry information.

Mysql > select * from my_table +-+ | id | mod_id | mod_name | +-- + | 1 | 20 | red | | 2 | 20 | blue | 3 | 20 | pink | | 4 | 21 | yellow | | 5 | 21 | green | | 6 | | | 21 | white | | 7 | 21 | black | | 8 | 30 | gray | | 9 | 30 | purple | | 10 | 30 | pinkpurple | 11 | 30 | red purple | +-+ 11 rows in set (0.00 sec) |

Original table data.

Mysql > select * from my_table where mod_name in ("red", 'blue',' pink', 'purple') +-red | 2 | 20 | blue | 3 | 20 | pink | 9 | 30 | purple | +- -+ 4 rows in set (0.00 sec)

Use the where condition query to match the columns in the list. (normal enquiry)

Mysql > select * from my_table where mod_name in ("red", 'blue',' pink' 'purple') +-1 | 20 | red | 2 | 20 | blue | 10 | 30 | pinkpurple | +-+ 3 rows in set (0.00 sec)

Note that the last set of values ('pink'' purple') is missing a comma, so the result of the query will be interpreted as the 'pinkpurple' string by default.

Mysql > select * from my_table where mod_name = ('pink'' purple') +-+ | id | mod_id | mod_name | +-+ | 10 | 30 | pinkpurple | +-+ 1 row in set (0.00 sec) use the = sign condition to query accurately Still interpreted as the result of a concatenation of two strings. Mysql > select * from my_table where mod_name = 'pink'' purple' +-+ | id | mod_id | mod_name | +-+ | 10 | 30 | pinkpurple | +-+ 1 row in set (0.00 sec) use the = sign condition to query precisely and remove the parenthesis. Still interpreted as the result of a concatenation of two strings. Mysql > select * from my_table where mod_name =''purple'' +-+ | id | mod_id | mod_name | +-+ | 9 | 30 | purple | +-+ 1 row in set (0.00 sec) the first string is a 0-length string, then the merge is equal to the purple string. Mysql > select * from my_table where mod_name = 'red''' 'purple';Empty set (.00 sec) writes three strings, where there is no space between the single quotation marks of the first string and the single quotation marks of the second string, so it is interpreted as an unknown character. Mysql > select * from my_table where mod_name = 'red'' purple' +-+ | id | mod_id | mod_name | +-+ | 11 | 30 | red purple | +-+ 1 row in set (0.00 sec) 'red'' purple' Each set of strings is separated by spaces and is merged into a red purple string.

Read the above about mysql string concatenation problem sharing, hope to give you some help in practical application. Due to the limited space in this article, it is inevitable that there will be deficiencies and need to be supplemented. If you need more professional answers, you can contact us on the official website for 24-hour pre-sales and after-sales to help you answer questions at any time.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database