~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-08-05 13:28:48 UTC
  • mto: This revision was merged to the branch mainline in revision 2395.
  • Revision ID: olafvdspek@gmail.com-20110805132848-vvwjg6pgwf56xnsd
Use const char* instead of str_ref

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Position Functions
 
2
==================
 
3
 
 
4
FIELD
 
5
-----
 
6
 
 
7
The FIELD function returns the index (position) of string arguments (str1, str2, str3, ...) 
 
8
 
 
9
It returns 0 if the str value is not found.
 
10
 
 
11
If each argument is a string, all arguments will be compared as strings, whereas if arguments are numbers, they will be compared as numbers.
 
12
 
 
13
Otherwise, the arguments are compared as double.
 
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().
 
16
 
 
17
.. code-block:: mysql
 
18
 
 
19
        SELECT FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo');
 
20
 
 
21
Returns 2
 
22
 
 
23
.. code-block:: mysql
 
24
        
 
25
        SELECT FIELD('fo', 'Hej', 'ej', 'Heja', 'hej', 'foo');
 
26
 
 
27
Returns 0
 
28
 
 
29
FIND_IN_SET
 
30
-----------
 
31
 
 
32
Return the index position of the first argument within the second argument
 
33
 
 
34
INSTR
 
35
-----
 
36
 
 
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
 
45
 
 
46
LEFT
 
47
----
 
48
 
 
49
Return the leftmost number of characters as specified
 
50
 
 
51
INSERT
 
52
------
 
53
 
 
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
 
 
73
 
 
74
LOCATE
 
75
------
 
76
 
 
77
Return the position of the first occurrence of substring.
 
78
 
 
79
POSITION
 
80
--------
 
81
 
 
82
A synonym for LOCATE()
 
83