~drizzle-trunk/drizzle/development

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