Strings

2023-10-31 11:17:11  Updated

A string is a sequence of characters enclosed in single quotation marks (') or double quotation marks (").

Note

If the ANSI_QUOTES mode is enabled, you can quote a string only by using single quotation marks. The statements for setting and querying the ANSI_QUOTES mode are as follows:

obclient> SET sql_mode = 'ANSI_QUOTES';
obclient> SELECT @@sql_mode;

OceanBase Database supports the following two types of strings:

  • Binary strings: The unit of a binary string is byte. Binary strings are compared based on their number of bytes. The character set and collation of a binary string are named binary.

  • Non-binary strings: The unit of a non-binary string is character. Some character sets support multi-byte characters. Non-binary strings are compared based on their number of characters. A non-binary string supports multiple character sets other than binary and collations that are compatible with the corresponding character sets.

To specify the character set and collation for a string, use the following COLLATE clause:

[_charset_name]'string' [COLLATE collation_name]

You can use escape characters in a string to express special meaning. An escape character starts with a backslash (\) followed by a certain sequence. Escape characters are case-sensitive. For example, \b indicates a backspace, and \B indicates the character B.

The following table lists all escape characters supported in OceanBase Database.

Escape character Description
\b A backspace.
\f A form feed.
\n A line feed.
\r A carriage return.
\t A tab character.
\\ A backslash (\).
\' A single quotation mark (').
\" A double quotation mark (").
\_ An underscore (_).
\% A percent sign (%).
\0 NULL
\Z The Ctrl-Z character. It is encoded by the number 26 in ASCII.

Contact Us