2. Language Elements : Expressions : Literals : String Literals
 
Share this page                  
String Literals
String literals are specified by one or more characters enclosed in single quotes. The default data type for string literals is varchar, but a string literal can be assigned to any character data type or to money or date data type without using a data type conversion function.
To compare a string literal with a non-character data type (A), you must either cast the string literal to the non-character data type A, or cast the non-character data type to the string literal type. Failure to do so causes unexpected results if the non-character data type contains the ‘NULL (0) value.
For example, to compare the function X string literal that returns a varchar data type to a byte data type, cast the result of the X function as follows:
SELECT * FROM uid_table
WHERE HEX(uid) = '010000000000000000000000000000'
Hexadecimal Representation
To specify a non-printing character in terminal monitor, use a hex (hexadecimal) constant. Hex constants are specified by an X followed by a single-quoted string composed of (an even number of) alphanumeric characters. For example, the following represents the ASCII string ABC<carriage return>:
X'4142430D'
A = X'41', B = X'42', C = X'43', and carriage return = X'OD'.
Quotes within Strings
To include a single quote inside a string literal, it must be doubled. For example:
'The following letter is quoted: ''A''.'
which is evaluated as:
The following letter is quoted: 'A'.