A string constant — or string literal — is a series of characters enclosed between a pair of apostrophes (“single quotes”). The maximum length of a string is 32,767 bytes; the maximum character count will be determined by the number of bytes used to encode each character.
The character set of a string constant is assumed to be the same as the character set of its destined storage.
String Constants in Hexadecimal Notation
From Firebird 2.5 forward, string literals can be entered in hexadecimal notation, so-called “binary strings”. Each pair of hex digits defines one byte in the string. Strings entered this way will have character set OCTETS
by default, but the introducer syntax can be used to force a string to be interpreted as another character set.
Syntax
Examples
Notes The client interface determines how binary strings are displayed to the user. The isql utility, for example, uses upper case letters A-F, while FlameRobin uses lower case letters. Other client programs may use other conventions, such as displaying spaces between the byte pairs: |
Introducer Syntax for String Literals
If necessary, a string literal may be preceded by a character set name, itself prefixed with an underscore “_”. This is known as introducer syntax. Its purpose is to inform the engine about how to interpret and store the incoming string.
Example
Number Constants (Literals)
A number constant — or number literal — is any valid number in a supported notation:
In SQL, for numbers in the standard decimal notation, the decimal point is always represented by period (
.
, full-stop, dot) character and thousands are not separated. Inclusion of commas, blanks, etc. will cause errors.Exponential notation is supported. For example, 0.0000234 can be expressed as
2.34e-5
.Hexadecimal notation is supported by Firebird 2.5 and higher versions — see below.
Hexadecimal Notation for Numbers
From Firebird 2.5 forward, integer values can be entered in hexadecimal notation. Numbers with 1-8 hex digits will be interpreted as type INTEGER
; numbers with 9-16 hex digits as type .
Syntax
Examples
Hex numbers between 8000 0000 .. FFFF FFFF require some attention:
When written with eight hex digits, as in
0x9E44F9A8
, a value is interpreted as 32-bitINTEGER
. Since the leftmost bit (sign bit) is set, it maps to the negative range -2147483648 .. -1 decimal.With one or more zeroes prepended, as in
0x09E44F9A8
, a value is interpreted as 64-bitBIGINT
in the range 0000 0000 8000 0000 .. 0000 0000 FFFF FFFF. The sign bit is not set now, so they map to the positive range 2147483648 .. 4294967295 decimal.
Thus, in this range — and only in this range — prepending a mathematically insignificant 0 results in a totally different value. This is something to be aware of.
Hex numbers between 1 0000 0000 .. 7FFF FFFF FFFF FFFF are all positive
BIGINT
.Hex numbers between 8000 0000 0000 0000 .. FFFF FFFF FFFF FFFF are all negative .