To store binary values or literals of fixed length without padding by additional zero (0) bytes or truncating trailing 0 bytes, use the Varbinary data type. To store binary data with indeterminate length, use the Blob data type instead. For more information, see Blob Data Type.

Binary literals begin with a prefix, 0h, followed by a string of hexadecimal numbers and are not enclosed with quotation marks (""), unlike character strings. The following list includes examples of binary literals:

Binary literals are limited to 255 encoded bytes. Varbinary fields are limited to 254 encoded bytes.

When performing comparison or concatenation operations, such as =, !=, ==, >, >=, <=, +, and -, the results vary depending on the operation and order of types in the operation. When you concatenate two binary values, the result is a binary value. When you concatenate variables of Varbinary (Q) type with Varchar (V) or Character (C) type, the result has the data type of the first item in the concatenation list. For example:

V + Q = V

Q + V = Q

When you compare between Varbinary and Character types, the type on the left side of the comparison expression governs the operation. For example, suppose a comparison expression such as the following is binary-based:

Q = V

Visual FoxPro evaluates these values on a byte for byte basis, and the result is the same as performing CAST(V AS Q(n) = Q.

Suppose the following comparison expression is character-based:

V = Q

Visual FoxPro evaluates these values as if they were character strings, and the result is the same as performing CAST(Q AS V(n) = V.

Index keys based on Varbinary fields or expressions are padded with zeros from the right of the value to the maximum length of the field. For example, the values 0hAA, 0hAA00, and 0hAA000 have the same index key of 0hAA0000. The default collation sequence for index keys based on binary expressions is MACHINE. No other collation sequences are permitted. For more information, see INDEX Command and Index Creation Based on Expressions.

Expand imageSupport for Varbinary Data Type

Expand imageSee Also