Chapter 59. UTL_RAW

Table of Contents

59.1. Overview
59.2. Functions
59.2.1. BIT_AND
59.2.2. BIT_COMPLEMENT
59.2.3. BIT_OR
59.2.4. BIT_XOR
59.2.5. CAST_FROM_BINARY_DOUBLE
59.2.6. CAST_FROM_BINARY_FLOAT
59.2.7. CAST_FROM_BINARY_INTEGER
59.2.8. CAST_FROM_NUMBER
59.2.9. CAST_TO_BINARY_DOUBLE
59.2.10. CAST_TO_BINARY_FLOAT
59.2.11. CAST_TO_BINARY_INTEGER
59.2.12. CAST_TO_NUMBER
59.2.13. CAST_TO_RAW
59.2.14. CAST_TO_VARCHAR2
59.2.15. COMPARE
59.2.16. CONCAT
59.2.17. COPIES
59.2.18. LENGTH
59.2.19. OVERLAY
59.2.20. REVERSE
59.2.21. SUBSTR
59.2.22. TRANSLATE
59.2.23. TRANSLITERATE
59.2.24. XRANGE

This chapter briefly introduces the UTL_RAW package, and describes how to use the functions of the package.

59.1. Overview

UTL_RAW provides various functions related to RAW type data.

In a SQL statement, functions that can be used for CHAR or VARCHAR data cannot be used for RAW data. Data conversion is not allowed among the RAW, CHAR, and VARCHAR types.

To solve this problem, functions defined in UTL_RAW can be used so that the functions used for CHAR and VARCHAR data can also be used for RAW data.

59.2. Functions

This section describes the functions provided by the UTL_RAW package, in alphabetical order.

59.2.1. BIT_AND

Returns the result of performing AND operation of two binary operands. If the lengths of the two operands are different, the result is as long as the longer operand.

Details about the BIT_AND function are as follows:

  • Prototype

    UTL_RAW.BIT_AND 
    (
        r1       IN          RAW,
        r2       IN          RAW
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    r1First operand.
    r2Second operand.
  • Return Value

    ValueDescription
    RAWReturns the AND of r1 and r2.
    NULLReturned if either r1 or r2 is NULL.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.BIT_AND('abc', '012'));
    END;
    /
    0010
    
    PSM completed
    SQL> 

59.2.2. BIT_COMPLEMENT

Returns the 1's complement of a binary data.

Details about the BIT_COMPLEMENT function are as follows:

  • Prototype

    UTL_RAW.BIT_COMPLEMENT
    (
        r       IN       RAW
    )  
    RETURN RAW;
  • Parameter

    ParameterDescription
    rOperand.
  • Return Value

    ValueDescription
    RAWReturns the COMPLEMENT of r.
    NULLReturned if r is NULL.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.BIT_COMPLEMENT('456'));
    END;
    /
    FBA9
    
    PSM completed
    SQL> 

59.2.3. BIT_OR

Performs an OR operation of two binary operands. If the lengths of the two operands are different, the result is as long as the longer operand.

Details about the BIT_OR function are as follows:

  • Prototype

    UTL_RAW.BIT_OR
    (
        r1       IN       RAW, 
        r2       IN       RAW
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    r1First operand.
    r2Second operand.
  • Return Value

    ValueDescription
    RAWReturns the OR of r1 and r2.
    NULLReturned if either r1 or r2 is NULL.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.BIT_OR('123', '456'));
    END;
    /
    0577
    
    PSM completed
    SQL> 

59.2.4. BIT_XOR

Performs an XOR operation for two binary operands. If the length of the two operands is different, the result is as long as the longer operand.

Details about the BIT_XOR function are as follows:

  • Prototype

    UTL_RAW.BIT_XOR
    (
        r1 IN RAW, 
        r2 IN RAW
    )  
    RETURN RAW;
  • Parameter

    ParameterDescription
    r1First operand.
    r2Second operand.
  • Return Value

    ValueDescription
    RAWReturns the XOR of r1 and r2.
    NULLReturned if either r1 or r2 is NULL.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.BIT_XOR('123', '456'));
    END;
    /
    0575
    
    PSM completed
    SQL> 

59.2.5. CAST_FROM_BINARY_DOUBLE

Converts a BINARY_DOUBLE value to RAW data. The length of the returned data is 8 bytes, and the specified endianness determines the byte order.

The endianess parameter represents the order in which bytes of RAW data is stored. If the system is little-endian, and the parameter is big-endian, the byte order of n is reversed, and if the parameter is little-endian, the bytes are stored in the same order as the byte order of the system.

Details about the CAST_FROM_BINARY_DOUBLE function are as follows:

  • Prototype

    UTL_RAW.CAST_FROM_BINARY_DOUBLE 
    (
        n              IN          BINARY_DOUBLE,
        endianess      IN          PLS_INTEGER     DEFAULT 1
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    nBINARY_DOUBLE value to convert.
    endianess

    Endianness.

    Either 1 (big-endian) or 2 (little-endian).

  • Return Value

    ValueDescription
    RAWReturns a binary representation of the BINARY_DOUBLE value.
    NULLReturned if the input value is NULL.
  • Exception

    ExceptionDescription
    INVALID_ENDIANOccurs when the endian value is not 1 or 2.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_FROM_BINARY_DOUBLE(1.5d));
    END;
    /
    3FF8000000000000
    
    PSM completed
    SQL> 

59.2.6. CAST_FROM_BINARY_FLOAT

Converts a BINARY_FLOAT value to RAW data. The length of the returned data is four bytes, and the specified endianness determines the byte order.

The endianess parameter represents the order in which bytes of RAW data is stored. If the system is little-endian, and the parameter is big-endian, the byte order of n is reversed, and if the parameter is little-endian, the bytes are stored in the same order as the byte order of the system.

Details about the CAST_FROM_BINARY_FLOAT function are as follows:

  • Prototype

    UTL_RAW.CAST_FROM_BINARY_FLOAT 
    (
        n              IN          BINARY_FLOAT,
        endianess      IN          PLS_INTEGER     DEFAULT 1
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    nBINARY_FLOAT value to convert
    endianess

    Endianness.

    Either 1 (big-endian) or 2 (little-endian).

  • Return Value

    ValueDescription
    RAWReturns a binary representation of the BINARY_FLOAT value.
    NULLReturned if the input value is NULL.
  • Exception

    ExceptionDescription
    INVALID_ENDIANOccurs when the endian value is not 1 or 2.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_FROM_BINARY_FLOAT(1.5f));
    END;
    /
    3FC00000
    
    PSM completed
    SQL> 

59.2.7. CAST_FROM_BINARY_INTEGER

Converts a BINARY_INTEGER value to RAW data. The length of the returned data is 4 bytes, and the specified endianness determines the byte order.

The endianess parameter represents the order in which bytes of RAW data is stored. If the system is little-endian, and the parameter is big-endian, the byte order of n is reversed, and if the parameter is little-endian, the bytes are stored in the same order as the byte order of the system.

Details about the CAST_FROM_BINARY_INTEGER function are as follows:

  • Prototype

    UTL_RAW.CAST_FROM_BINARY_INTEGER 
    (
        n              IN          BINARY_INTEGER,
        endianess      IN          PLS_INTEGER         DEFAULT 1
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    nBINARY_INTEGER value to convert
    endianess

    Endianness.

    Either 1 (big-endian) or 2 (little-endian).

  • Return Value

    ValueDescription
    RAWReturns a binary representation of the BINARY_INTEGER value.
    NULLReturned if the input value is NULL.
  • Exception

    ExceptionDescription
    INVALID_ENDIANOccurs when the endian value is not 1 or 2.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_FROM_BINARY_INTEGER(10));
    END;
    /
    0000000A
    
    PSM completed
    SQL> 

59.2.8. CAST_FROM_NUMBER

Converts a NUMBER value to RAW data. The returned binary data is the Tibero internal binary format, and its length is variable depending on the input value.

The endianess parameter represents the order in which bytes of RAW data is stored. If the system is little-endian, and the parameter is big-endian, the byte order of n is reversed, and if the parameter is little-endian, the bytes are stored in the same order as the byte order of the system.

Details about the CAST_FROM_NUMBER function are as follows:

  • Prototype

    UTL_RAW.CAST_FROM_NUMBER 
    (
        n           IN          NUMBER
    )  
    RETURN RAW;
  • Parameter

    ParameterDescription
    nNUMBER value to convert.
  • Return Value

    ValueDescription
    RAWReturns a binary representation of the NUMBER value.
    NULLReturned if the input value is NULL.
  • Exception

    ExceptionDescription
    INVALID_ENDIANOccurs when the endian value is not 1 or 2.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_FROM_NUMBER(1.5));
    END;
    /
    03C181B2
    
    PSM completed
    SQL> 

59.2.9. CAST_TO_BINARY_DOUBLE

Converts a RAW value in BINARY_DOUBLE data. The length of the input binary data is 8 bytes.

Details about the CAST_TO_BINARY_DOUBLE function are as follows:

  • Prototype

    UTL_RAW.CAST_TO_BINARY_DOUBLE 
    (
        r              IN          RAW,
        endianess      IN          PLS_INTEGER     DEFAULT 1
    ) 
    RETURN BINARY_DOUBLE;
  • Parameter

    ParameterDescription
    rBinary data to convert
    endianess

    Endianness.

    Either 1 (big-endian) or 2 (little-endian).

  • Return Value

    ValueDescription
    BINARY_DOUBLEReturns the value converted from RAW data to BINARY_DOUBLE data.
    NULLReturned if the input value is NULL.
  • Exception

    ExceptionDescription
    INVALID_ENDIANOccurs when the endian value is not 1 or 2.
  • Example

    DECLARE
        bin raw(100);
    BEGIN
        bin := UTL_RAW.CAST_FROM_BINARY_DOUBLE(1.5d);
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_TO_BINARY_DOUBLE(bin));
    END;
    /
    1.5E+00
    
    PSM completed
    SQL> 

59.2.10. CAST_TO_BINARY_FLOAT

Converts a RAW value to BINARY_FLOAT data. The length of the input binary data is 4 bytes.

Details about the CAST_TO_BINARY_FLOAT function are as follows:

  • Prototype

    UTL_RAW.CAST_TO_BINARY_FLOAT 
    (
         r              IN          RAW,
         endianess      IN          PLS_INTEGER     DEFAULT 1
    ) 
    RETURN BINARY_FLOAT;
  • Parameter

    ParameterDescription
    rBinary data to convert.
    endianess

    Endianness.

    Either 1 (big-endian) or 2 (little-endian).

  • Return Value

    ValueDescription
    BINARY_FLOATReturns the value converted from RAW data to BINARY_FLOAT data.
    NULLReturned if the input value is NULL.
  • Exception

    ExceptionDescription
    INVALID_ENDIANOccurs when the endian value is not 1 or 2.
  • Example

    DECLARE
        bin raw(100);
    BEGIN
        bin := UTL_RAW.CAST_FROM_BINARY_FLOAT(1.5f);
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_TO_BINARY_FLOAT(bin));
    END;
    /
    1.5E+00
    
    PSM completed
    SQL> 

59.2.11. CAST_TO_BINARY_INTEGER

Converts a RAW value to BINARY_INTEGER data. The length of the input binary data is 4 bytes.

Details about the CAST_TO_BINARY_INTEGER function are as follows:

  • Prototype

    UTL_RAW.CAST_TO_BINARY_INTEGER 
    (
        r              IN          RAW,
        endianess      IN          PLS_INTEGER     DEFAULT 1
    ) 
    RETURN BINARY_INTEGER;
  • Parameter

    ParameterDescription
    rBinary data to convert.
    endianess

    Endianness.

    Either 1 (big-endian) or 2 (little-endian).

  • Return Value

    ValueDescription
    BINARY_INTEGERReturns the value converted from RAW data to BINARY_INTEGER data.
    NULLReturned if the input value is NULL.
  • Exception

    ExceptionDescription
    INVALID_ENDIANOccurs when the endian value is not 1 or 2.
  • Example

    DECLARE
        bin raw(100);
    BEGIN
        bin := UTL_RAW.CAST_FROM_BINARY_INTEGER(777);
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_TO_BINARY_INTEGER(bin));
    END;
    /
    777
    
    PSM completed
    SQL> 

59.2.12. CAST_TO_NUMBER

Converts a RAW value to NUMBER data. The returned binary data is the Tibero internal binary format, and its length is variable depending on the input value.

Details about the CAST_TO_NUMBER function are as follows:

  • Prototype

    UTL_RAW.CAST_TO_NUMBER
    (
        r           IN          RAW
    )  
    RETURN NUMBER;
  • Parameter

    ParameterDescription
    rBinary data to convert.
  • Return Value

    ValueDescription
    NUMBERReturns the value converted from RAW data to NUMBER data.
    NULLReturned if the input value is NULL.
  • Exception

    ExceptionDescription
    INVALID_ENDIANOccurs when the endian value is not 1 or 2.
  • Example

    DECLARE
        bin raw(100);
    BEGIN
        bin := UTL_RAW.CAST_FROM_NUMBER(1004);
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_TO_NUMBER(bin));
    END;
    /
    1004
    
    PSM completed
    SQL> 

59.2.13. CAST_TO_RAW

Converts a VARCHAR type string into RAW data. The input is a string representation of the RAW data.

Details about the CAST_TO_RAW function are as follows:

  • Prototype

    UTL_RAW.CAST_TO_RAW 
    (
        c        IN          VARCHAR2
    )  
    RETURN RAW;
  • Parameter

    ParameterDescription
    cString to convert.
  • Return Value

    ValueDescription
    RAWReturns a binary representation of VARCHAR2.
    NULLReturned if the input value is NULL.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_TO_RAW('0a3bcf'));
    END;
    /
    306133626366
    
    PSM completed
    SQL> 

59.2.14. CAST_TO_VARCHAR2

Converts a RAW type string to VARCHAR2 data. The output is a string representation of binary data.

Details about the CAST_TO_VARCHAR2 function are as follows:

  • Prototype

    UTL_RAW.CAST_TO_VARCHAR2 
    (
        r           IN          RAW
    )  
    RETURN VARCHAR2;
  • Parameter

    ParameterDescription
    rBinary data to convert.
  • Return Value

    ValueDescription
    VARCHAR2Returns the value converted from RAW data to VARCHAR2 data.
    NULLReturned if the input value is NULL.
  • Example

    DECLARE
        bin RAW(100);
    BEGIN
        bin := UTL_RAW.CAST_TO_RAW('Nanobase');
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_TO_VARCHAR2(bin));
    END;
    /
    Nanobase
    
    PSM completed
    SQL> 

59.2.15. COMPARE

Compares two RAW operands. If the two operands differ in length, the shorter operand is padded so that the lengths of the two operands are the same.

Details about the COMPARE function are as follows:

  • Prototype

    UTL_RAW.COMPARE 
    (
        r1          IN          RAW,
        r2          IN          RAW,
        pad         IN          RAW     DEFAULT NULL
    ) 
    RETURN INTEGER;
  • Parameter

    ParameterDescription
    r1First operand.
    r2Second operand.
    pad

    Bytes to append to the shorter operand.

    Default value: '00'

  • Return Value

    ValueDescription
    0Returned if both r1 and r2 are NULL, or their lengths are exactly the same.
    N >= 1Returns the position where byte values of r1 and r2 are different.
  • Example

    DECLARE
        x RAW(20) := UTL_RAW.CAST_TO_RAW('ABCDEF');
        y RAW(20) := UTL_RAW.CAST_TO_RAW('ABCDFF');
    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.COMPARE(x, y));
    END;
    /
    5
    
    PSM completed
    SQL> 

59.2.16. CONCAT

Concatenates up to 12 RAW data. This function can have from 1 to 12 input parameters. The maximum length of the concatenated binary data is 32,767 bytes. If the resulting data length exceeds this limit, the ERROR_EXP_CONCAT_TOO_LONG error occurs.

Details about the CONCAT function are as follows:

  • Prototype

    UTL_RAW.CONCAT 
    (
        r1       IN          RAW,
        r2       IN          RAW,
        r3       IN          RAW,
        r4       IN          RAW,
        r5       IN          RAW,
        r6       IN          RAW,
        r7       IN          RAW,
        r8       IN          RAW,
        r9       IN          RAW,
        r10      IN          RAW,
        r11      IN          RAW,
        r12      IN          RAW
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    r1, ..., r12

    Binary data to concatenate.

    Up to 12 parameters can be used.

  • Return Value

    ValueDescription
    RAWReturns the concatenated RAW data.
    NULLReturned if all the input values are NULL.
  • Example

    DECLARE
        x RAW(100) := UTL_RAW.CAST_TO_RAW('Give me liberty');
        y RAW(100) := UTL_RAW.CAST_TO_RAW(', or give me death');
        z RAW(200);
    BEGIN
        z := UTL_RAW.CONCAT(x, y);
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_TO_VARCHAR2(z));
    END;
    /
    Give me liberty, or give me death
    
    PSM completed
    SQL> 

59.2.17. COPIES

Concatenates n copies of a RAW data. If the data is longer than 32,767 bytes, an exception occurs.

Details about the COPIES function are as follows:

  • Prototype

    UTL_RAW.COPIES 
    (
        r               IN          RAW, 
        n               IN          NUMBER 
    )  
    RETURN RAW;
  • Parameter

    ParameterDescription
    rBinary data to copy.
    nNumber of times to copy the RAW data.
  • Exception

    ExceptionDescription
    VALUE_ERROR
    • Occurs if r is NULL.

    • Occurs if n is less than 1.

    • Occurs if the returned data is longer than 32,767 bytes.

  • Example

    DECLARE
        x VARCHAR2(100);
        y RAW(200);
        z RAW(200);
    BEGIN
        x := 'Books are ships which pass ';
        x := x || 'through the vast seas of time';
        y := UTL_RAW.CAST_TO_RAW(x);
        z := UTL_RAW.COPIES(y, 1);
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.CAST_TO_VARCHAR2(z));
    END;
    /
    Books are ships which pass through the vast seas of time
    
    PSM completed
    SQL> 

59.2.18. LENGTH

Returns the length of a RAW data in bytes.

Details about the LENGTH function are as follows:

  • Prototype

    UTL_RAW.LENGTH 
    (
        r        IN          RAW
    )  
    RETURN INTEGER;
  • Parameter

    ParameterDescription
    rBinary data to return the length of.
  • Return Value

    ValueDescription
    NUMBERReturns the data length.
    NULLReturned if the input value is NULL.
  • Example

    DECLARE
        x RAW(20) := UTL_RAW.CAST_TO_RAW('Out of mind');
    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.LENGTH(x));
    END;
    /
    11
    
    PSM completed
    SQL> 

59.2.19. OVERLAY

Overlays RAW source data with RAW target data. The source data which starts from the position specified by pos and whose length is specified by len is copied over the target data.

If the source data is shorter than len, the remaining part is filled with bytes of pad. If the target data is shorter than pos, the pad bytes fill the space from the beginning to the position at pos, and then the source data is copied.

This function returns the data created by copying the source data over the target data without updating the actual target data. The returned data must not be longer than 32,767 bytes.

Details about the OVERLAY function are as follows:

  • Prototype

    UTL_RAW.OVERLAY
    (
        overlay_str     IN          RAW,
        target          IN          RAW,
        pos             IN          BINARY_INTEGER  DEFAULT 1,
        len             IN          BINARY_INTEGER  DEFAULT NULL,
        pad             IN          RAW             DEFAULT NULL
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    overlay_strSource binary data.
    targetTarget binary data.
    posPosition in the target binary data. Must be greater than or equal to 1.
    len

    Length of the source data to overlay. Must be greater than or equal to 0.

    If set to NULL, all of the data is overlayed.

    pad

    Pad byte.

    Default value: '00'

  • Exception

    ExceptionDescription
    VALUE_ERROR
    • Occurs if the source data is NULL or its length is 0.

    • Occurs if the target data is NULL.

    • Occurs if pos is less than 1, or len is greater than 0.

    • Occurs if the returned binary data is longer than 32,767 bytes.

  • Example

    DECLARE
        bin RAW(100);
    BEGIN
        bin := UTL_RAW.OVERLAY('ee', 'fabcdff', 2, 3, '12');
        DBMS_OUTPUT.PUT_LINE(bin);
    END;
    /
    0FEE1212
    
    PSM completed
    SQL> 

59.2.20. REVERSE

Reverses the byte order of a RAW data. The length of the returned binary data is the same as that of the input binary data.

Details about the REVERSE function are as follows:

  • Prototype

    UTL_RAW.REVERSE 
    (
        data        IN          RAW
    )  
    RETURN RAW;
  • Parameter

    ParameterDescription
    dataBinary data to reverse.
  • Exception

    ExceptionDescription
    VALUE_ERROROccurs when the input data is NULL or its length is 0.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.REVERSE('abcd132'));
    END;
    /
    32D1BC0A
    
    PSM completed
    SQL> 

59.2.21. SUBSTR

Returns all or a part of a RAW data that is len bytes long starting at the position specified in pos. If the binary data is NULL, NULL is returned.

Details about the SUBSTR function are as follows:

  • Prototype

    UTL_RAW.SUBSTR
    (
        data            IN          RAW,
        pos             IN          BINARY_INTEGER,
        len             IN          BINARY_INTEGER      DEFAULT NULL
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    dataBinary data.
    pos

    Offset position in the binary data.

    • If pos is greater than or equal to 1, it represents a position starting from the beginning of the binary data.

    • If pos is –1 or less, it represents a position starting from the end of the binary data.

    • pos cannot be 0.

    len

    Length of data to return.

    If set to NULL, all data from pos to the end of the binary data is returned.

  • Exception

    ExceptionDescription
    VALUE_ERROROccurs when the parameter pos is 0, or the parameter len is less than 1.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.SUBSTR('abc1234', 2, 2));
    END;
    /
    BC12
    
    PSM completed
    SQL> 

59.2.22. TRANSLATE

Translates specified bytes of RAW data. If a byte in from_set exist in the binary data, the byte is replaced by the byte in the corresponding position in to_set. If to_set is too short to include the corresponding byte in the same position, it is replaced by a blank byte.

This function returns the translated data without modifying the input binary data.

Details about the TRANSLATE function are as follows:

  • Prototype

    UTL_RAW.TRANSLATE 
    (
        data            IN          RAW,
        from_set        IN          RAW,
        to_set          IN          RAW
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    dataBinary data.
    from_setByte-codes to translate.
    to_setByte-codes to translate to.
  • Exception

    ExceptionDescription
    VALUE_ERROROccurs when the parameter from_set or to_set is NULL, or if either of the length is 0.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.TRANSLATE('abcde', 'bc', '77'));
    END;
    /
    0A77DE
    
    PSM completed
    SQL> 

59.2.23. TRANSLITERATE

Converts specified bytes of a RAW data. If a byte in from_set exist in the binary data, the byte is replaced by the byte in the corresponding position in to_set. If to_set is too short to include the corresponding byte in the same position, it is replaced by the pad byte.

This function returns the translated data without modifying the input binary data.

Details about the TRANSLITERATE function are as follows:

  • Prototype

    UTL_RAW.TRANSLITERATE 
    (
        data            IN          RAW,
        to_set          IN          RAW     DEFAULT NULL,
        from_set        IN          RAW     DEFAULT NULL,
        pad             IN          RAW     DEFAULT NULL
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    dataBinary data.
    from_setByte-codes to translate.
    to_setByte-codes to translate to.
    pad

    1-byte used if to_set is shorter than from_set.

    Only 1 byte of the input value is used regardless of the actual length of the input.

  • Exception

    ExceptionDescription
    VALUE_ERROROccurs when data is NULL or its length is 0.
  • Example

    DECLARE
        bin RAW(100);
    BEGIN
        bin := UTL_RAW.TRANSLITERATE('abcde', 'cd', 'bcde');
        DBMS_OUTPUT.PUT_LINE(bin);
    END;
    /
    0ACD00
    
    PSM completed
    SQL> 

59.2.24. XRANGE

Returns a RAW data with all bytes in order starting from the start_byte and ending with the end_byte. If start_byte is larger than end_byte, it starts with the start_byte, wraps from 0xFF to 0x00, and ends at the end_byte.

Details about the XRANGE function are as follows:

  • Prototype

    UTL_RAW.XRANGE 
    (
        start_byte      IN          RAW     DEFAULT NULL,
        end_byte        IN          RAW     DEFAULT NULL
    ) 
    RETURN RAW;
  • Parameter

    ParameterDescription
    start_byteFirst byte of the result.
    end_byteLast byte of the result.
  • Example

    BEGIN
        DBMS_OUTPUT.PUT_LINE(UTL_RAW.XRANGE('a', 'd'));
    END;
    /
    0A0B0C0D
    
    PSM completed
    SQL>