~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-16 23:33:54 UTC
  • mfrom: (1994.4.76 drizzle)
  • mto: This revision was merged to the branch mainline in revision 2174.
  • Revision ID: kalebral@gmail.com-20110216233354-qc8rcc4uoq4h0uqr
Merge Marisa - 716062 - fix ubuntu install doc

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
        SELECT ASCII('0');
 
11
 
 
12
Returns 48 ::
 
13
 
 
14
        SELECT ASCII('d');
 
15
 
 
16
Returns 100
 
17
 
 
18
 
 
19
BIN
 
20
---
 
21

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. 
 
22
 
 
23
Syntax:
 
24
 
 
25
BIN (N);
 
26
 
 
27
For exempt: ::
 
28
 
 
29
        SELECT BIN(12);
 
30
 
 
31
Returns: '1100'
 
32
 
 
33
 
 
34
CHAR
 
35
----
 
36

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: ::
 
38
 
 
39
        SELECT CHAR(65) AS ch_65;
 
40
 
 
41
Returns "A"

 
42
 
 
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
 
 
70
        SELECT UNHEX('4452495A5AHc45');
 
71
 
 
72
Returns 'drizzle' ::
 
73
 
 
74
        SELECT UNHEX(HEX('string'));
 
75
 
 
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
 
 
86
Returns NULL
 
87
 
 
88
 
 
89
 
 
90
LOWER()                   
 
91
Return the argument in lowercase
 
92
 
 
93
 
 
94
LCASE()                   
 
95
Synonym for LOWER()
 
96
 
 
97
 
 
98
UCASE()                   
 
99
Synonym for UPPER()
 
100
 
 
101
 
 
102
UPPER()                   
 
103
Convert to uppercase