~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/functions/string/comparative.rst

Adds support for '.' in option:: names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Comparative Functions
 
2
=====================
 
3
 
 
4
LIKE            
 
5
----
 
6
 
 
7
The LIKE operator is used to check if field values match a specified pattern, and searches for less-than-exact but similar values.
 
8
 
 
9
An initial example is:
 
10
 
 
11
.. code-block:: mysql
 
12
 
 
13
        SELECT 'ä' LIKE 'ae' COLLATE latin1_german2_ci;
 
14
 
 
15
Returns 0
 
16
 
 
17
Whereas:
 
18
 
 
19
.. code-block:: mysql
 
20
 
 
21
        SELECT 'ä' = 'ae' COLLATE latin1_german2_ci;
 
22
 
 
23
Returns 1
 
24
 
 
25
The LIKE operator supports the use of two wildcards. (Wildcards provide more flexibility by allowing any character or group of characters in a string to be acceptable as a match for another string):
 
26
 
 
27
    * Percentage (%): Represents zero or more values.
 
28
    * Underscore (_): Matches exactly one character value.
 
29
 
 
30
In accordance the SQL standard, LIKE performs matching on a per-character basis. It therefore provides results different from the = comparison operator.
 
31
 
 
32
The following SELECT statement includes a WHERE clause in order to search for job titles that start with "DIRECTOR", by using the percentage wildcard after the lookup value.
 
33
 
 
34
For example:
 
35
 
 
36
.. code-block:: mysql
 
37
 
 
38
        SELECT title, field
 
39
        FROM job_detail
 
40
        WHERE title LIKE 'DIRECTOR%'
 
41
        ORDER BY field, title;
 
42
 
 
43
 
 
44
REGEXP
 
45
------
 
46
 
 
47
Returns values that match a regular expression pattern; they are commonly used for creating complex searches. Here is an example of using a REGEXP (Regular Expression) match:
 
48
 
 
49
.. code-block:: mysql
 
50
 
 
51
        SELECT title, category_name
 
52
        FROM film_detail
 
53
        WHERE title REGEXP '^AIRP[LO]'
 
54
        ORDER BY title;
 
55
 
 
56
Other REGEXP examples:
 
57
 
 
58
.. code-block:: mysql
 
59
 
 
60
        SELECT 'abcabc' REGEXP 'abc',    
 
61
        'abcabc' REGEXP 'cb';
 
62
 
 
63
The search pattern may describe only a part of string. To match entire string, use ^ and $ in the search:
 
64
 
 
65
.. code-block:: mysql
 
66
 
 
67
        SELECT 'abc' REGEXP '^abc$', 'abcabc' REGEXP '^abc$';
 
68
 
 
69
        SELECT 'cde' REGEXP '[a-c]+', 'efg' REGEXP '[a-c]+';
 
70
 
 
71
        SELECT 'abcabc' REGEXP 'ABC', 'abcabc' REGEXP BINARY 'ABC';
 
72
 
 
73
 
 
74
STRCMP()
 
75
--------
 
76
 
 
77
The purpose of STRCMP is also to compare two strings. This function returns 0 if two strings are the same, -1 if the first argument is smaller than the second according to the current sort order, and 1 otherwise.