~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Comparative Functions
 
2
=====================
 
3
 
 
4
.. _like-function:
 
5
 
 
6
LIKE            
 
7
----
 
8
 
 
9
The LIKE operator is used to check if field values match a specified pattern, and searches for less-than-exact but similar values.
 
10
 
 
11
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):
 
12
 
 
13
    * Percentage (%): Represents zero or more values.
 
14
    * Underscore (_): Matches exactly one character value.
 
15
 
 
16
In accordance the SQL standard, LIKE performs matching on a per-character basis. It therefore provides results different from the = comparison operator.
 
17
 
 
18
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.
 
19
 
 
20
For example:
 
21
 
 
22
.. code-block:: mysql
 
23
 
 
24
        SELECT title, field
 
25
        FROM job_detail
 
26
        WHERE title LIKE 'DIRECTOR%'
 
27
        ORDER BY field, title;
 
28
 
 
29
.. _regex-function:
 
30
 
 
31
REGEX
 
32
-----
 
33
 
 
34
Undocumented.
 
35
 
 
36
.. _regexp-function:
 
37
 
 
38
REGEXP
 
39
------
 
40
 
 
41
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:
 
42
 
 
43
.. code-block:: mysql
 
44
 
 
45
        SELECT title, category_name
 
46
        FROM film_detail
 
47
        WHERE title REGEXP '^AIRP[LO]'
 
48
        ORDER BY title;
 
49
 
 
50
Other REGEXP examples:
 
51
 
 
52
.. code-block:: mysql
 
53
 
 
54
        SELECT 'abcabc' REGEXP 'abc',    
 
55
        'abcabc' REGEXP 'cb';
 
56
 
 
57
The search pattern may describe only a part of string. To match entire string, use ^ and $ in the search:
 
58
 
 
59
.. code-block:: mysql
 
60
 
 
61
        SELECT 'abc' REGEXP '^abc$', 'abcabc' REGEXP '^abc$';
 
62
 
 
63
        SELECT 'cde' REGEXP '[a-c]+', 'efg' REGEXP '[a-c]+';
 
64
 
 
65
        SELECT 'abcabc' REGEXP 'ABC', 'abcabc' REGEXP BINARY 'ABC';
 
66
 
 
67
.. _strcmp-function:
 
68
 
 
69
STRCMP
 
70
------
 
71
 
 
72
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.