~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Lee Bieber
  • Date: 2011-02-24 03:20:47 UTC
  • mfrom: (2196.1.4 build)
  • Revision ID: kalebral@gmail.com-20110224032047-avmw06iwww3m73cw
Merge Andrew - 723653: Docs day first pass fixes 
Merge Brian - Puts back in support for COM_KILL, Also adds back in the INTERACTIVE flag, and creates a DD to track sessions/check on usage
Merge Olaf - Use List::size()

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
-----
6
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
7
 
8
 
For example:  ::
 
8
For example:
 
9
 
 
10
.. code-block:: mysql
9
11
 
10
12
        SELECT ASCII('0');
11
13
 
12
 
Returns 48 ::
 
14
Returns 48
 
15
 
 
16
.. code-block:: mysql
13
17
 
14
18
        SELECT ASCII('d');
15
19
 
24
28
 
25
29
BIN (N);
26
30
 
27
 
For exempt: ::
 
31
For exempt:
 
32
 
 
33
.. code-block:: mysql
28
34
 
29
35
        SELECT BIN(12);
30
36
 
34
40
CHAR
35
41
----
36
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.   

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

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