A string literal is a sequence of characters enclosed in single quotes. For example, 'Hello world'
is a string literal of type CHAR. Its byte length is 11, and its character length is also 11.
A string literal is sometimes referred to as a string constant, literal string, or just as a string. In SQL Anywhere, the preferred term is string literal.
You can specify an NCHAR string literal by prefixing the quoted value with N. For example, N'Hello world'
is a string literal of type NCHAR. Its byte length is 11, and its character length is 11. The bytes within an NCHAR string
literal are interpreted using the database's CHAR character set, and then converted to NCHAR. The syntax N'string'
is a shortened form for CAST( 'string' AS NCHAR )
.
Sometimes you need to put characters into string literals that cannot be typed or entered normally. Examples include control characters (such as a new line character), single quotes (which would otherwise mark the end of the string literal), and hexadecimal byte values. For this purpose, you use an escape sequence.
The following examples show how to use escape sequences in string literals.
A single quote is used to mark the beginning and end of a string literal, so a single quote in a string must be escaped using
an additional single quote, as follows: 'John''s database'
A backslash followed by any character other than n, x, X, or \ is interpreted as two separate characters. For example, \q inserts a backslash and the letter q.
Hexadecimal escape sequences can be used for any character or binary value. A hexadecimal escape sequence is a backslash followed
by an x followed by two hexadecimal digits. The hexadecimal value is interpreted as a character in the CHAR character set
for both CHAR and NCHAR string literals. The value \x09 must be coded as \\x09 if you don't want the value stored as a single
tab character, but \xyy would be stored as \xyy. The following example, in code page 1252, represents the digits 1, 2, and
3, followed by the euro currency symbol: '123\x80'
.
A backslash character in a string must be escaped using an additional backslash, as follows: 'c:\\november'
. For paths, you can also use the forward slash (/) instead of a backslash: 'c:/november'
.
To represent a new line character, use a backslash followed by n (\n), specify: 'First line:\nSecond line:'
You can use the same characters and escape sequences with NCHAR string literals as with CHAR string literals.
If you need to use Unicode characters that cannot be typed directly into the string literal, use the UNISTR function. See UNISTR function [String].
![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |