~sharan-monikantan/drizzle/crashme

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2012-06-22 06:48:16 UTC
  • mfrom: (2535.5.17 drizzle-7.1)
  • Revision ID: brian@tangent.org-20120622064816-c1n7dczhxffddlsr
Merge docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
Conversion Functions
2
2
====================
3
3
 
 
4
'TODO'
 
5
 
4
6
.. _ascii-function:
5
7
 
6
8
ASCII
7
9
-----
8
10
 
9
 
The ASCII(str) function returns the numeric value of the leftmost character of the string ’str’. It returns NULL if str is NULL. It works for 8-bit characters.
10
 
 
11
 
For example:
12
 
 
13
 
.. code-block:: mysql
14
 
 
15
 
        SELECT ASCII('0');
16
 
 
17
 
Returns 48
18
 
 
19
 
.. code-block:: mysql
20
 
 
21
 
        SELECT ASCII('d');
22
 
 
23
 
Returns 100
24
11
 
25
12
.. _bin-function:
26
13
 
27
14
BIN
28
15
---
29
16
 
30
 
The BIN string function returns a string value that represents the binary value of N, where N is a longlong(BIGINT) number. This function is equivalent to CONV(N, 10 , 0). If the function return the null then N is null. 
31
 
 
32
 
Syntax:
33
 
 
34
 
BIN (N);
35
 
 
36
 
For exempt:
37
 
 
38
 
.. code-block:: mysql
39
 
 
40
 
        SELECT BIN(12);
41
 
 
42
 
Returns: '1100'
43
 
 
44
 
 
45
17
.. _char-function:
46
18
 
47
19
CHAR
48
20
----
49
21
 
50
 
SQL CHAR function is the opposite of the ASCII function. It converts an integer in range 0-255 into a ASCII character. It returns a string (the character), given the integer value. This function skips NULL values.   

51
 
For example:
52
 
 
53
 
.. code-block:: mysql
54
 
 
55
 
        SELECT CHAR(65) AS ch_65;
56
 
 
57
 
Returns "A"

58
22
 
59
23
.. _hex-function:
60
24
 
61
25
HEX
62
26
---
63
27
 
64
 
This string function returns the hexadecimal (base-16) representation of a string or decicmal argument. Each character in the string argument is converted to two hexadecimal digits. If the argument is numeric, HEX() returns a hexadecimal string representation of the value as a BIGINT number.
65
 
 
66
 
Using HEX for numeric values:
67
 
 
68
 
.. code-block:: mysql
69
 
 
70
 
        SELECT HEX(255);
71
 
 
72
 
Returns: FF
73
 
 
74
 
Using HEX for string values:
75
 
 
76
 
.. code-block:: mysql
77
 
 
78
 
        SELECT HEX('Drizzle');
79
 
 
80
 
Returns: 4452495A5AHc45
81
 
 
82
 
(To better understand this output, you can use an :doc:`../../resources/ascii_chart` that includes both Hexadecimal and character values.)
83
28
 
84
29
.. _unhex-function:
85
30
 
86
31
UNHEX
87
32
-----
88
33
 
89
 
UNHEX converts each pair of hexadecimal digits to a character. For a string argument, UNHEX() is the inverse operation of HEX(str).
90
 
 
91
 
Instead of converting each character in the string argument to hex digits, it interprets each pair of characters in the argument as a hexadecimal number and converts it to the character represented by the number. The return value is a binary string.
92
 
 
93
 
.. code-block:: mysql
94
 
 
95
 
        SELECT UNHEX('4452495A5AHc45');
96
 
 
97
 
Returns 'drizzle'
98
 
 
99
 
.. code-block:: mysql
100
 
 
101
 
        SELECT UNHEX(HEX('string'));
102
 
 
103
 
Returns 'string'
104
 
 
105
 
.. code-block:: mysql
106
 
 
107
 
        SELECT HEX(UNHEX('1267'));
108
 
 
109
 
Returns '1267'
110
 
 
111
 
The characters in the argument string must be legal hexadecimal digits: '0' .. '9', 'A' .. 'F', 'a' .. 'f'. If the argument contains any non-hexadecimal digits, the result is NULL:
112
 
 
113
 
.. code-block:: mysql
114
 
 
115
 
        SELECT UNHEX('GG');
116
 
 
117
 
Returns NULL
 
34
 
118
35
 
119
36
.. _lower-function:
120
37
 
121
38
LOWER
122
39
-----
123
40
 
124
 
Return the argument in lowercase.
125
41
 
126
42
.. _lcase-function:
127
43
 
128
44
LCASE
129
45
-----
130
46
 
131
 
Synonym for LOWER().
132
47
 
133
48
.. _ucase-function:
134
49
 
135
50
UCASE
136
51
-----
137
52
 
138
 
Synonym for UPPER()
139
53
 
140
54
.. _upper-function:
141
55
 
142
56
UPPER
143
57
-----
144
58
 
145
 
Convert to uppercase.
 
59