1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
Position Functions
==================
.. _field-function:
FIELD
-----
The FIELD function returns the index (position) of string arguments (str1, str2, str3, ...)
It returns 0 if the str value is not found.
If each argument is a string, all arguments will be compared as strings, whereas if arguments are numbers, they will be compared as numbers.
Otherwise, the arguments are compared as double.
If str is NULL, the return value is 0 because NULL fails equality comparison with any value. FIELD() is the complement of ELT().
.. code-block:: mysql
SELECT FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo');
Returns 2
.. code-block:: mysql
SELECT FIELD('fo', 'Hej', 'ej', 'Heja', 'hej', 'foo');
Returns 0
.. _find-in-set-function:
FIND_IN_SET
-----------
Return the index position of the first argument within the second argument
.. code-block:: mysql
SELECT FIND_IN_SET('2', '1,2,3,4');
-> 2
SELECT FIND_IN_SET('1', '123');
-> 0
.. _instr-function:
INSTR
-----
INSTR(str, substr) returns the index of the first occurrence of substring str in string substr. Note that this works like LOCATE except the order of the arguments is reversed:
.. code-block:: mysql
SELECT INSTR('tacosalad', 'salad');
-> 5
SELECT INSTR('burger', 'salad');
-> 0
.. _left-function:
LEFT
----
Return the leftmost number of characters as specified
.. code-block:: mysql
SELECT LEFT('drizzled', 7);
-> 'drizzle'
.. _insert-function:
INSERT
------
This function inserts a substring at the specified position up to the specified number of characters.
INSERT(str,pos,len,newstr)
It returns str (a string), with the substring beginning at pos (position) and len (how many characters long) replaced by the newstr.
* INSERT returns the original string if pos is not within the length of the string
* It replaces the rest of the string from position pos if len is not within the length of the rest of the string
* It returns NULL if any argument is NULL
.. code-block:: mysql
SELECT INSERT('Aquatic', 3, 2, 'Me');
-> 'AqMetic'
SELECT INSERT('Aquatic', -1, 4, 'This');
-> 'Aquatic'
SELECT INSERT('Aquatic', 3, 100, 'This');
-> 'AqThis'
.. _locate-function:
LOCATE
------
Return the position of the first occurrence of substring.
.. code-block:: mysql
SELECT LOCATE('salad', 'tacosalad');
-> 5
SELECT LOCATE('burger', 'salad');
-> 0
.. _position-function:
POSITION
--------
A synonym for LOCATE()
|