|
Sybernet / Supplied Packages Reference
Release 3.00 May 25, 2008 |
|
The TRANSLATE package provides subprograms for translating strings between different character sets. Supported character sets include Ascii, EBCDIC, and Hexadecimal. Because 4-bit character strings are not supported in Oracle, all translations to Hexadecimal must occur with an even number of characters. This makes sense because it is impossible to assign one half of a byte to null.
You will also find two functions for URI Encoding and URI Decoding a string in this package. There are two other functions for encoding and decoding strings suitable for Javascript.
| Subprogram | Description |
|---|---|
ASCIITOEBCDIC |
Translates a string from Ascii to EBCDIC. |
ASCIITOHEX |
Translates a string from Ascii to Hexadecimal. |
EBCDICTOASCII |
Translates a string from EBCDIC to Ascii. |
EBCDICTOHEX |
Translate a string from EBCDIC to Hexadecimal. |
HEXTOASCII |
Translates a string from Hexadecimal to Ascii. |
HEXTOEBCDIC |
Translates a string from Hexadecimal to EBCDIC. |
HTTPDECODE |
Decodes an HTML string containing HTML escape sequences. |
HTTPENCODE |
Encodes an HTML string with HTML escape sequences. |
JSDECODE |
Decodes a JavaScript string. |
JSENCODE |
Encodes a JavaScript string. |
URLDECODE |
Decodes a URI. |
URLENCODE |
Encodes a URI. |
ASCIITOEBCDIC translates a string from Ascii to EBCDIC. This overloaded subprogram can be called as a function which accepts a string of Ascii characters and returns a string of EBCDIC characters or as a procedure which accepts a string of Ascii characters and passes them (after translation) to HTTP.WRITE.
Function ASCIITOEBCDIC
(
SRC IN VARCHAR2
)
RETURN VARCHAR2;
| Parameter | Description |
|---|---|
src |
The Ascii characters to be translated. |
Procedure ASCIITOEBCDIC
(
SRC IN VARCHAR2
) ;
| Parameter | Description |
|---|---|
src |
The Ascii string to be translated. |
The following example illustrates how to call ASCIITOEBCDIC:
declare
src varchar(10) := '0123456789';
begin
http.translate.ebcdictoascii(http.translate.asciitoebcdic(src));
end;
ASCIITOHEX translates a string from Ascii to Hexadecimal. This overloaded subprogram can be called as a function which accepts one Ascii character that returns its decimal value or as a procedure which accepts a variable length string that writes its Hexadecimal representation. The length of the output parameter is exactly one half of the input parameter. An exception is raised if the input paramter's length is not an even number.
Function ASCIITOHEX
(
C IN CHAR
)
RETURN NUMBER;
| Parameter | Description |
|---|---|
c |
The Ascii character to be translated. |
Procedure ASCIITOHEX
(
SRC IN VARCHAR2
) ;
| Parameter | Description |
|---|---|
src |
The Ascii string to be translated. |
The following example illustrates how to call ASCIITOHEX:
declare
src varchar(20) := '30313233343536373839';
begin
http.translate.asciitohex(src);
end;
EBCDICTOASCII translate a string from EBCDIC to Ascii. This overloaded subprogram can be
called as a function which accepts a string of EBCDIC characters and returns a string of Ascii characters or as
a procedure which accepts a string of EBCDIC characters and passes them (after translation) to HTTP.WRITE.
Function EBCDICTOASCII
(
SRC IN VARCHAR2
)
RETURN CHAR;
| Parameter | Description |
|---|---|
src |
The EBCDIC string to be translated. |
Procedure EBCDICTOASCII
(
SRC IN VARCHAR2
) ;
| Parameter | Description |
|---|---|
src |
The EBCDIC string to be translated. |
The following example illustrates how to call EBCDICTOASCII:
declare
src varchar(10) := '0123456789';
begin
http.translate.ebcdictoascii(http.translate.asciitoebcdic(src));
end;
EBCDICTOHEX translates a string from EBCDIC to Hexadecimal. This overloaded subprogram can be called as a function which accepts one EBCDIC character that returns its decimal value or as a procedure which accepts a variable length string.
Function EBCDICTOHEX
(
C IN CHAR
)
RETURN NUMBER;
| Parameter | Description |
|---|---|
c |
The EBCDIC character to be translated. |
Procedure EBCDICTOHEX
(
SRC IN VARCHAR2
) ;
| Parameter | Description |
|---|---|
src |
The EBCDIC string to be translated. |
The following example illustrates how to call EBCDICTOHEX:
declare
src varchar(20) := '30313233343536373839';
begin
http.translate.ebcdictohex(http.translate.asciitoebcdic(src));
end;
HEXTOASCII translates a string from Hexadecimal to Ascii. This overloaded subprogram can be called as a function which accepts a numeric value (0 through 15) that returns its corresponding Ascii character or as a procedure which accepts a variable length string that is translated to Ascii.
Function HEXTOASCII
(
I IN NUMBER
)
RETURN CHAR;
| Parameter | Description |
|---|---|
i |
A numeric Hexadecimal value (0 through 15). |
Procedure HEXTOASCII
(
SRC IN VARCHAR2
) ;
| Parameter | Description |
|---|---|
src |
The Hexadecimal string to be translated. |
The following example illustrates how to call HEXTOASCII:
declare
src varchar(12) := 'Hello World';
begin
http.translate.hextoascii(src);
end;
HEXTOEBCDIC translates a string from Hexadecimal to EBCDIC. This overloaded subprogram can be called as a function which accepts a numeric value (0 through 15) that returns its corresponding EBCDIC character or as a procedure which accepts a variable length string that is translated to EBCDIC.
Function HEXTOEBCDIC
(
I IN NUMBER
)
RETURN CHAR;
| Parameter | Description |
|---|---|
i |
A numeric Hexadecimal value (0 through 15). |
Procedure HEXTOEBCDIC
(
SRC IN VARCHAR2
) ;
| Parameter | Description |
|---|---|
src |
The Hexadecimal string to be translated. |
The following example illustrates how to call HEXTOEBCDIC:
declare
src varchar(10) := '9';
begin
http.translate.ebcdictoascii(http.translate.hextoebcdic(src));
end;
JSDECODE decodes a JavaScript string. Special characters in JavaScript strings like tab characters and quotation marks must be escaped. This function decodes such strings.
Function JSDECODE
(
SRC VARCHAR2
)
RETURN VARCHAR2;
| Parameter | Description |
|---|---|
src |
The string to be decoded. |
The following example illustrates how to call JSDECODE:
declare
var varchar(30) := '\"This string is quoted\"';
begin
http.write(http.translate.jsdecode(var));
end;
JSENCODE encodes a JavaScript string. Special characters in JavaScript strings like tab characters and quotation marks must be escaped. This function encodes such strings.
Function JSENCODE
(
SRC VARCHAR2
)
RETURN VARCHAR2;
| Parameter | Description |
|---|---|
src |
The string to be encoded. |
The following example illustrates how to call JSENCODE:
declare
var varchar(30) := '"This ''string'' is quoted"';
begin
http.writeln
(
'<script>'
, 'var'
, ' s = "' || http.translate.jsencode(var) || '"'
, ' ;'
, ' alert(s);'
, '</script>'
) ;
end;
URLDECODE decodes a URI string. Special characters in URI's like tab characters and quotation marks must be escaped. This function decodes such strings. Letters and numbers are not special characters and do not require URI encoding, but this function will decode strings containing these characters as well.
Function URLDECODE
(
URL VARCHAR2
)
RETURN VARCHAR2;
| Parameter | Description |
|---|---|
url |
The string to be URI decoded. |
The following example illustrates how to call URLDECODE:
declare
var varchar(30) := '%22This string is quoted%22';
begin
http.write(http.translate.urldecode(var));
end;
HTTPDECODE decodes an HTML string. These are strings that contain HTML escape sequences like " and ". If this function is unable to decode an escape sequence (because it is invalid), the sequence is left untouched.
Function HTTPDECODE
(
SRC VARCHAR2
)
RETURN VARCHAR2;
| Parameter | Description |
|---|---|
src |
The string to be HTML decoded. |
The following example illustrates how to call HTTPDECODE:
declare
var varchar(30) := 'Hello World';
begin
http.write(http.translate.httpdecode(var));
end;
HTTPENCODE encodes an HTML string. Although HTTPDECODE will decode any HTML escape sequence, this function encodes only a subset of all possible values. The reason for this is that in general use it isn't necessary to escape space characters, for example. What is escaped includes double-quotes, single-quotes, less-than and greater-than signs.
Function HTTPENCODE
(
SRC VARCHAR2
)
RETURN VARCHAR2;
| Parameter | Description |
|---|---|
src |
The string to be HTML encoded. |
The following example illustrates how to call HTTPENCODE:
declare
var varchar(30) := '"Hello World"';
begin
http.write(http.translate.httpdecode(var));
end;
The following example illustrates a practical use of this function when invoking a javascript function that wants to pass the parameter NAME (containing, for example, double-quotes). In this example notice that we are in a single quoted string which contains a double-quoted string which then needs to escape the use of double-quotes inside of that string, and worst of all the parameter we are passing contains yet another double-quoted string:
declare
name varchar(30) := 'Cleaver,Theodore "Beaver"';
begin
http.javascript.script(true);
http.writeln
(
'function displayEmployee(name)'
, '{'
, ' alert(name);'
, ' return;'
, '}'
, 'window.document.write("<a href=\"javascript:displayEmployee(''' || http.translate.httpencode(name) || ''');\">The Beaver</a>");'
) ;
http.javascript.script(false);
end;
URLENCODE encodes a URI string. Special characters in URI's like tab characters and quotation marks must be escaped. This function encodes such strings. Letters and numbers are not special characters and do not require URI encoding.
Function URLENCODE
(
URL VARCHAR2
)
RETURN VARCHAR2;
| Parameter | Description |
|---|---|
url |
The string to be URI encoded. |
The following example illustrates how to call URLENCODE:
declare
var varchar(30) := '"This string is quoted"';
begin
http.write(http.translate.urlencode(var));
end;