String with exact length : Introduction « Regular Expression « SQL / MySQL






String with exact length

    
/*
mysql> select * from Bird;
+----------+-------+---------+------+------------+------------+
| name     | owner | species | sex  | birth      | death      |
+----------+-------+---------+------+------------+------------+
| BlueBird | Joe   | Car     | f    | 1999-03-30 | NULL       |
| RedBird  | Yin   | Bus     | m    | 1979-04-30 | 0000-00-00 |
| RedBird  | Yin   | Bus     | m    | 1998-01-30 | NULL       |
+----------+-------+---------+------+------------+------------+
3 rows in set (0.00 sec)

mysql> SELECT * FROM Bird WHERE name LIKE '_______';
+---------+-------+---------+------+------------+------------+
| name    | owner | species | sex  | birth      | death      |
+---------+-------+---------+------+------------+------------+
| RedBird | Yin   | Bus     | m    | 1979-04-30 | 0000-00-00 |
| RedBird | Yin   | Bus     | m    | 1998-01-30 | NULL       |
+---------+-------+---------+------+------------+------------+
2 rows in set (0.00 sec)


*/  
Drop table Bird;

CREATE TABLE Bird (
    name VARCHAR(20), 
    owner VARCHAR(20),
    species VARCHAR(20), 
    sex CHAR(1), 
    birth DATE, 
    death DATE
);
  
INSERT INTO  Bird VALUES ('BlueBird','Joe','Car','f','1999-03-30',NULL);
INSERT INTO  Bird VALUES ('RedBird','Yin','Bus','m','1979-04-30',1998-01-30);
INSERT INTO  Bird VALUES ('RedBird','Yin','Bus','m','1998-01-30',NULL);
  
select * from Bird;
/*
names containing exactly five characters, 
use five instances of the '_' pattern character:
*/
SELECT * FROM Bird WHERE name LIKE '_______';



           
         
    
    
    
  








Related examples in the same category

1.Regular Expressions
2.Group the alternatives within parentheses, the ^ and $ will apply to both of them
3.The asterisk (*) indicates zero or more.
4.Limit the match on the 'i' to either zero or one.
5.As the plus sign (+) indicates that g had to appear one or more times
6.{3,} means the a must occur at least three times
7.MySQL's regular expression capabilities also support POSIX character classes.
8.Using Operators in Your SQL Statements
9.If you wish to encompass the entire character string, you must use ^ and $ in the search:
10.Name and regular expression
11.String case in regular expression
12.Where clause: regular expressions
13.Where clause: regular expression 2
14.show records where the name has 6 characters
15.A regular expression matches anywhere in the string.
16.Match only aaa
17.To match abcabcabc, you need to use parentheses
18.Regular expression and postcode
19.Regular expression and street value
20.Regular expression: or
21.Parentheses indicate an entire character string, and curly braces indicate how many times the character string
22.Square brackets indicate a selection from among several characters, a hyphen is used to indicate a range of ch