~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
String Modification Functions
2
 
=============================
3
 
 
4
 
CONCAT
5
 
------
6
 
 
7
 
The SQL standard defines a concatenation operator ( || ), which joins two or more strings into one string value.
8
 
The CONCAT(str1, str2...) function can have one or more arguments. It returns a string that is the result of concatenating the arguments.
9
 
 
10
 
* If arguments are non-binary strings, the result is also a non-binary string.
11
 
* If any argument is a binary string, then the result will also be a binary string. 
12
 
* Numeric arguments are converted to their equivalent in binary string format. 
13
 
* If any argument is NULL then it also returns NULL. 
14
 
 
15
 
Syntax:
16
 
 
17
 
CONCAT(str1, str2, [,...n])
18
 
For example:
19
 
 
20
 
.. code-block:: mysql
21
 
 
22
 
        SELECT CONCAT('Dr', 'izzl', 'ed');
23
 
 
24
 
Returns: 'Drizzled'
25
 
 
26
 
.. code-block:: mysql
27
 
 
28
 
        SELECT CONCAT('micro', NULL, 'nel');
29
 
 
30
 
Returns: NULL
31
 
 
32
 
.. code-block:: mysql
33
 
 
34
 
        SELECT CONCAT(14.8);
35
 
 
36
 
Returns: '14.8'
37
 
 
38
 
CONCAT_WS
39
 
---------
40
 
CONCAT WS (With Separator) [1]_ allows you to specify that the first argument is treated as a separator for the rest of the arguments. This argument is added between the strings to be concatenated.
41
 
 
42
 
Syntax:
43
 
 
44
 
CONCAT_WS(separator str1, str2,....)
45
 
 
46
 
For example:
47
 
 
48
 
.. code-block:: mysql
49
 
 
50
 
        SELECT CONCAT_WS(',', ' Occupation', 'First name', 'Last Name');
51
 
 
52
 
Returns: 'Occupation, First name, Last Name'
53
 
 
54
 
.. code-block:: mysql
55
 
 
56
 
        SELECT CONCAT_WS(',', 'First name', NULL, 'Last Name');
57
 
 
58
 
Returns: 'First name, Last Name'
59
 
 
60
 
 
61
 
TRIM()
62
 
------
63
 
 
64
 
The TRIM function remove specified prefixes or suffixes from a string (typically leading and trailing spaces), and returns the resulting string. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed.
65
 
 
66
 
Syntax:
67
 
 
68
 
TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr FROM] str)
69
 
 
70
 
[remstr] is optional (if it's not specified, spaces are removed).
71
 
 
72
 
LTRIM()
73
 
-------
74
 
 
75
 
This version of the TRIM function removes leading spaces from the beginning of a string.
76
 
 
77
 
 
78
 
RTRIM()
79
 
-------
80
 
 
81
 
This version of the TRIM function removes trailing spaces from the end of a function. 
82
 
 
83
 
.. rubric:: Footnotes
84
 
 
85
 
.. [1] If the separator is NULL then the result is NULL.