To make a pattern match case sensitive, use a binary string for either operand : Patterns « Regular Expression « SQL / MySQL






To make a pattern match case sensitive, use a binary string for either operand

       
mysql>
mysql> CREATE TABLE mytable
    -> (
    ->  name    VARCHAR(20)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO mytable (name)
    ->  VALUES
    ->          ('copper'),
    ->          ('gold'),
    ->          ('iron'),
    ->          ('lead'),
    ->          ('mercury'),
    ->          ('platinum'),
    ->          ('silver'),
    ->          ('tin')
    -> ;
Query OK, 8 rows affected (0.00 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql>
mysql> SELECT * FROM mytable;
+----------+
| name     |
+----------+
| copper   |
| gold     |
| iron     |
| lead     |
| mercury  |
| platinum |
| silver   |
| tin      |
+----------+
8 rows in set (0.00 sec)

mysql>
mysql>
mysql> SELECT name, name LIKE '%i%%', name REGEXP 'i' FROM mytable;
+----------+------------------+-----------------+
| name     | name LIKE '%i%%' | name REGEXP 'i' |
+----------+------------------+-----------------+
| copper   |                0 |               0 |
| gold     |                0 |               0 |
| iron     |                1 |               1 |
| lead     |                0 |               0 |
| mercury  |                0 |               0 |
| platinum |                1 |               1 |
| silver   |                1 |               1 |
| tin      |                1 |               1 |
+----------+------------------+-----------------+
8 rows in set (0.00 sec)

mysql>
mysql>
mysql> drop table mytable;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
    
    
  








Related examples in the same category

1.Pattern match: string has 5 characters
2.Pattern match: letter repeats
3.Pattern in Where clause
4.Using Pattern Matching
5.Pattern Matching
6.Show records where the name matches a search pattern
7.Matching Pattern Metacharacters Literally
8.To match a literal instance of a SQL pattern metacharacter, precede it with a backslash:
9.Pattern Matching with Regular Expressions