Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Reference » SQL Functions » Alphabetical list of functions

BYTE_LENGTH function [String] Next Page

BYTE_SUBSTR function [String]

Returns a substring of a string. The substring is calculated using bytes, not characters.


BYTE_SUBSTR( string-expression, start [, length ] )


string-expression    The string from which the substring is taken.

start    An integer expression indicating the start of the substring. A positive integer starts from the beginning of the string, with the first character being position 1. A negative integer specifies a substring starting from the end of the string, the final character being at position -1.

length    An integer expression indicating the length of the substring. A positive length specifies the number of bytes to be taken starting at the start position. A negative length returns at most length bytes up to, and including, the starting position, from the left of the starting position.


If length is specified, the substring is restricted to that number of bytes. Both start and length can be either positive or negative. Using appropriate combinations of negative and positive numbers, you can get a substring from either the beginning or end of the string.

If start is zero and length is non-negative, a start value of 1 is used. If start is zero and length is negative, a start value of -1 is used.

This function supports NCHAR inputs and/or outputs.

See also
Standards and compatibility

The following statement returns the value Test.

SELECT BYTE_SUBSTR( 'Test Message', 1, 4 );