The uuencode() function encodes a binary value as ASCII by using the UNIX UUencode format.
The encoding translates the binary value into ASCII character codes in the range 32 and above. Historically, uuencoding is used to encode files destined for email transmission. The uudecode() function reverses the effect of uuencode(), re-creating the original binary file exactly.
| Value type | Input character | Input character | Input character |
|---|---|---|---|
| Original ASCII Input | h | a | t |
| ASCII Decimal | 104 | 97 | 116 |
| ASCII Binary (8 bit) | 01101000 | 01100001 | 01110100 |
Steps 2 and 3 are illustrated by the following table. The transformation of the three 8 bit ASCII Binary values in the preceding table to the four 6 bit Binary values in the first line of the table:
| Value type | Input value | Input value | Input value | Input value |
|---|---|---|---|---|
| 6 Bit Binary | 011010 | 000110 | 000101 | 110100 |
| Decimal Equivalent | 26 | 6 | 5 | 52 |
| Decimal + 32 | 58 | 38 | 37 | 84 |
| Uuencoding | : | & | % | T |
varchar = uuencode(varchar input);
nvarchar = uuencode(nvarchar input);
The input value specifies the binary value to be uuencoded.
select uuencode ('hat');
UUENCODE
--------------------
begin
#:&%T
'
end
(1 row)
For uuencode() and uudecode(), the begin/end header information is important. If the header information is removed from the output of uuencode() and the encoded string is passed to uudecode(), the uudecode() function returns “ERROR: 0 : Invalid UUData”.