In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Today, a colleague said that he wrote a sql statement that there was no result in the query.
SELECT * FROM Persons WHERE City LIKE'[BLN]%'
Then let's do it again:
SQL wildcards are statements that use special characters or grammatical spelling to execute fuzzy search instructions. When querying data in a database, SQL wildcards can replace one or more characters. Must be used with the LIKE operator. The wildcards that can be used in SQL are:
Wildcard character
Description%
Replace one or more characters
-replace only one character [charlist] any single character in the character column [^ charlist] or [! charlist] that is not in the character column
"%": matches any number of characters (zero or more); "_": matches any single character
You can use LIKE or NOT LIKE comparison operators when using wildcards, not = or! =
Take user table as an example:
Query records ending in a: select * from user where username like'% a'
Query the user name starting with a: select * from user where username like'a%'
The query does not start with a user name: select * from user where username like'a%'
Query the user name containing a: select * from user where username like'% a%'
Query a user name with two characters: select * from user where username like'_ _'
The point is here:
Other types of MySQL pattern matching are extended regular expressions, using the REGEXP and NOT REGEXP operators (or RLIKE and NOT RLIKE, and then you can check LIKE and RLIKE yourself when you encounter HIVE).
Some of the characters that extend regular expressions are:
"." Matches any single character, a character class "[.]" Match any characters in brackets such as "[abc]" matches "a", "b" or "c". To name a range of characters, use a connector "-". "[amurz]" matches any lowercase letter, while "[0-9]" matches any number.
"*" matches zero or more things in front of it. For example, "x*" matches any number of "x" characters, "[0-9] *" matches any number of numbers, and ". *" matches any number of characters.
In addition, regular expressions are case-sensitive, of course, you can use a character class colleague to match case such as "[aA]" matches lowercase or uppercase "a" and "[a-zA-Z]" matches any letter of both.
To locate a pattern to match the beginning or end of the target value, use "^" at the beginning of the pattern or "$" at the end of the pattern. Here is how to write a LIKE query using REGEXP:
Query city for information about people who start with "L", use "^" to match the beginning of the name and "[lL]" to match lowercase or uppercase "l"
Select * from Persons where City REGEXP "^ [lL]"
Query the person whose lastname ends with "sh" and use "$" to match the end of the name:
SELECT * FROM Persons WHERE LastName REGEXP "sh$"
Query lastname contains an "A" person, using "[aA]" to match lowercase or uppercase "a":
SELECT * FROM Persons WHERE LastName REGEXP "[aA]"
Query a record with exactly 6 characters in the city name, using "^" and "$" to match the beginning and end of the name, and 6 "." The instance is between the two:
SELECT * FROM Persons WHERE city REGEXP "^. $"
You can also use the "{n}"repeat n times" operator:
SELECT * FROM pet WHERE name REGEXP "^. {6} $"
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.