~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Conversion Functions
====================

.. _ascii-function:

ASCII
-----

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.

For example:

.. code-block:: mysql

	SELECT ASCII('0');

Returns 48

.. code-block:: mysql

	SELECT ASCII('d');

Returns 100

.. _bin-function:

BIN
---

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. 

Syntax:

BIN (N);

For exempt:

.. code-block:: mysql

	SELECT BIN(12);

Returns: '1100'


.. _char-function:

CHAR
----

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.   

For example:

.. code-block:: mysql

	SELECT CHAR(65) AS ch_65;

Returns "A"


.. _hex-function:

HEX
---

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.

Using HEX for numeric values:

.. code-block:: mysql

	SELECT HEX(255);

Returns: FF

Using HEX for string values:

.. code-block:: mysql

	SELECT HEX('Drizzle');

Returns: 4452495A5AHc45

(To better understand this output, you can use an :doc:`../../resources/ascii_chart` that includes both Hexadecimal and character values.)

.. _unhex-function:

UNHEX
-----

UNHEX converts each pair of hexadecimal digits to a character. For a string argument, UNHEX() is the inverse operation of HEX(str).

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.

.. code-block:: mysql

	SELECT UNHEX('4452495A5AHc45');

Returns 'drizzle'

.. code-block:: mysql

	SELECT UNHEX(HEX('string'));

Returns 'string'

.. code-block:: mysql

	SELECT HEX(UNHEX('1267'));

Returns '1267'

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:

.. code-block:: mysql

	SELECT UNHEX('GG');

Returns NULL

.. _lower-function:

LOWER
-----

Return the argument in lowercase.

.. _lcase-function:

LCASE
-----

Synonym for LOWER().

.. _ucase-function:

UCASE
-----

Synonym for UPPER()

.. _upper-function:

UPPER
-----

Convert to uppercase.