~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Olaf van der Spek
  • Date: 2011-04-05 12:26:58 UTC
  • mto: (2278.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2272.
  • Revision ID: olafvdspek@gmail.com-20110405122658-xxrvmobwwwwf3oct
Refactor Open_tables_state

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
FIELD
5
5
-----
6
6
 
7
 
The FIELD function returns the index (position) of string arguments (str1, str2, str3, â€¦.) 
 
7
The FIELD function returns the index (position) of string arguments (str1, str2, str3, ...) 
8
8
 
9
9
It returns 0 if the str value is not found.
10
10
 
12
12
 
13
13
Otherwise, the arguments are compared as double.
14
14
 
15
 
If str is NULL, the return value is 0 because NULL fails equality comparison with any value. FIELD() is the complement of ELT(). ::
 
15
If str is NULL, the return value is 0 because NULL fails equality comparison with any value. FIELD() is the complement of ELT().
 
16
 
 
17
.. code-block:: mysql
16
18
 
17
19
        SELECT FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo');
18
20
 
19
 
Returns 2 ::
 
21
Returns 2
 
22
 
 
23
.. code-block:: mysql
20
24
        
21
25
        SELECT FIELD('fo', 'Hej', 'ej', 'Heja', 'hej', 'foo');
22
26
 
30
34
INSTR
31
35
-----
32
36
 
33
 
Return the index of the first occurrence of substring
 
37
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:
 
38
 
 
39
.. code-block:: mysql
 
40
 
 
41
        SELECT INSTR('tacosalad', 'salad');
 
42
                -> 4
 
43
        SELECT INSTR('burger', 'salad');
 
44
                -> 0
34
45
 
35
46
LEFT
36
47
----
40
51
INSERT
41
52
------
42
53
 
43
 
Insert a substring at the specified position up to the specified number of characters
 
54
This function inserts a substring at the specified position up to the specified number of characters.
 
55
 
 
56
INSERT(str,pos,len,newstr)
 
57
 
 
58
It returns str (a string), with the substring beginning at pos (position) and len (how many characters long) replaced by the newstr. 
 
59
 
 
60
* INSERT returns the original string if pos is not within the length of the string
 
61
* It replaces the rest of the string from position pos if len is not within the length of the rest of the string
 
62
* It returns NULL if any argument is NULL
 
63
 
 
64
.. code-block:: mysql
 
65
 
 
66
        SELECT INSERT('Aquatic', 3, 2, 'Me');
 
67
                -> 'AqMetic'
 
68
        SELECT INSERT('Aquatic', -1, 4, 'This');
 
69
                -> 'Aquatic'
 
70
        SELECT INSERT('Aquatic', 3, 100, 'This');
 
71
                -> 'AqThis'
 
72
 
44
73
 
45
74
LOCATE
46
75
------
47
76
 
48
 
Return the position of the first occurrence of substring
 
77
Return the position of the first occurrence of substring.
49
78
 
50
79
POSITION
51
80
--------