~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Mark Atwood
  • Date: 2011-08-11 03:05:03 UTC
  • mfrom: (2385.1.12 refactor4)
  • Revision ID: me@mark.atwood.name-20110811030503-rp9xjihc5x3y0x4q
merge lp:~olafvdspek/drizzle/refactor4

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
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):
 
10
 
 
11
    * Percentage (%): Represents zero or more values.
 
12
    * Underscore (_): Matches exactly one character value.
 
13
 
 
14
In accordance the SQL standard, LIKE performs matching on a per-character basis. It therefore provides results different from the = comparison operator.
 
15
 
 
16
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.
 
17
 
 
18
For example:
 
19
 
 
20
.. code-block:: mysql
 
21
 
 
22
        SELECT title, field
 
23
        FROM job_detail
 
24
        WHERE title LIKE 'DIRECTOR%'
 
25
        ORDER BY field, title;
 
26
 
 
27
 
 
28
REGEXP
 
29
------
 
30
 
 
31
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:
 
32
 
 
33
.. code-block:: mysql
 
34
 
 
35
        SELECT title, category_name
 
36
        FROM film_detail
 
37
        WHERE title REGEXP '^AIRP[LO]'
 
38
        ORDER BY title;
 
39
 
 
40
Other REGEXP examples:
 
41
 
 
42
.. code-block:: mysql
 
43
 
 
44
        SELECT 'abcabc' REGEXP 'abc',    
 
45
        'abcabc' REGEXP 'cb';
 
46
 
 
47
The search pattern may describe only a part of string. To match entire string, use ^ and $ in the search:
 
48
 
 
49
.. code-block:: mysql
 
50
 
 
51
        SELECT 'abc' REGEXP '^abc$', 'abcabc' REGEXP '^abc$';
 
52
 
 
53
        SELECT 'cde' REGEXP '[a-c]+', 'efg' REGEXP '[a-c]+';
 
54
 
 
55
        SELECT 'abcabc' REGEXP 'ABC', 'abcabc' REGEXP BINARY 'ABC';
 
56
 
 
57
 
 
58
STRCMP()
 
59
--------
 
60
 
 
61
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.