~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

merge lp:~linuxjedi/drizzle/trunk-remove-drizzleadmin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Conversion Functions
 
2
====================
 
3
 
 
4
ASCII
 
5
-----
 
6

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.
 
7
 
 
8
For example:
 
9
 
 
10
.. code-block:: mysql
 
11
 
 
12
        SELECT ASCII('0');
 
13
 
 
14
Returns 48
 
15
 
 
16
.. code-block:: mysql
 
17
 
 
18
        SELECT ASCII('d');
 
19
 
 
20
Returns 100
 
21
 
 
22
 
 
23
BIN
 
24
---
 
25

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. 
 
26
 
 
27
Syntax:
 
28
 
 
29
BIN (N);
 
30
 
 
31
For exempt:
 
32
 
 
33
.. code-block:: mysql
 
34
 
 
35
        SELECT BIN(12);
 
36
 
 
37
Returns: '1100'
 
38
 
 
39
 
 
40
CHAR
 
41
----
 
42

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.   

 
43
For example:
 
44
 
 
45
.. code-block:: mysql
 
46
 
 
47
        SELECT CHAR(65) AS ch_65;
 
48
 
 
49
Returns "A"

 
50
 
 
51
HEX()
 
52
-----
 
53
 
 
54
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.
 
55
 
 
56
Using HEX for numeric values:
 
57
 
 
58
.. code-block:: mysql
 
59
 
 
60
        SELECT HEX(255);
 
61
 
 
62
Returns: FF
 
63
 
 
64
Using HEX for string values:
 
65
 
 
66
.. code-block:: mysql
 
67
 
 
68
        SELECT HEX('Drizzle');
 
69
 
 
70
Returns: 4452495A5AHc45
 
71
 
 
72
(To better understand this output, you can use an :doc:`../../resources/ascii_chart` that includes both Hexadecimal and character values.)
 
73
 
 
74
 
 
75
UNHEX()
 
76
-------
 
77
 
 
78
UNHEX converts each pair of hexadecimal digits to a character. For a string argument, UNHEX() is the inverse operation of HEX(str).
 
79
 
 
80
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.
 
81
 
 
82
.. code-block:: mysql
 
83
 
 
84
        SELECT UNHEX('4452495A5AHc45');
 
85
 
 
86
Returns 'drizzle'
 
87
 
 
88
.. code-block:: mysql
 
89
 
 
90
        SELECT UNHEX(HEX('string'));
 
91
 
 
92
Returns 'string'
 
93
 
 
94
.. code-block:: mysql
 
95
 
 
96
        SELECT HEX(UNHEX('1267'));
 
97
 
 
98
Returns '1267'
 
99
 
 
100
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:
 
101
 
 
102
.. code-block:: mysql
 
103
 
 
104
        SELECT UNHEX('GG');
 
105
 
 
106
Returns NULL
 
107
 
 
108
 
 
109
LOWER()                   
 
110
Return the argument in lowercase
 
111
 
 
112
 
 
113
LCASE()                   
 
114
Synonym for LOWER()
 
115
 
 
116
 
 
117
UCASE()
 
118
Synonym for UPPER()
 
119
 
 
120
 
 
121
UPPER()                   
 
122
Convert to uppercase