In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to convert mysql into varchar, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Mysql transform varchar method: 1, use cast function conversion; 2, use "select-(- field name) from table name;" way conversion; 3, use "select field name + 0 from table name;" way conversion.
This article operating environment: windows7 system, mysql5.5 version, Dell G3 computer.
MySQL varchar type conversion:
Problem: do the data filtering module, because there is a problem with the original table design, the field in the table is a string, and the filter condition is numeric, so there is no way to compare.
Think about it: you can extract the numbers from the string in the mysql field and compare them
Solution: access to data and find three methods
1. Use the cast function
For example: SELECT CAST (field name AS UNSIGNED) FROM table name
The syntax rule for the cast function is: Cast (the type of field name as conversion), where the type can be:
CHAR [(N)] representative: character type DATE representative: date type DATETIME representative: date type DECIMAL representative: float type SIGNED representative: int TIME representative: time type
For a string at the beginning of a number, the result of conversion to a number is to intercept the previous part of the number, but for a string that cannot intercept a number at the beginning, the result of the conversion is 0, which requires attention.
two。 Use-(- field name)
For example: select-(- field name) from table name
This is more powerful, simple and rough.
3. Use the field name directly + 0
For example: select field name + 0 from table name
This is only used for numbers with all varchar types in the field, and cannot contain Chinese or anything else, otherwise an error will be reported. It is generally recommended to use 1BI 2.
Thank you for reading this article carefully. I hope the article "how to convert mysql to varchar" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.