SQL — PCK() Function

Syntax

PCK(num1,num2)

Description

The PCK() function (and counterpart UPK() function) has been added for compatibility with older Business BASICs that support these non-standard capabilities. In the syntax, num1 is any numeric expression, and num2 is an integer from 1 to 6. The string result will be num2 bytes long. The packed string may hold two digits per byte; therefore, a 6-byte packed string may hold a 12-digit number (including a sign). If num1 has any fractional digits, they will be ignored. If the value is too large for the size of the packed result, then the excess digits on the left will be discarded.

The intent of PCK() and UPK() functions is to allow compression of numeric values into a pseudo-binary form to preserve disk space. Because the BIN() function might generate bytes that could be mistaken for field terminators (by the READ statement), another method was needed.

The PCK() and UPK() functions are designed so that the packed strings will not contain field terminators. In order to be consistent with other implementations of PCK() and UPK(), the packed string for negative values will compare greater than a packed string for positive values. Additionally, a packed string for -2 will compare greater than a packed string for -1 (even though, numerically, -1 is greater than -2). The BASIS DBMS does not necessarily use the same packed format as some other BASICs; therefore, when converting existing data files for use with the BASIS Database, packed fields must be unpacked and then repacked using the BASIS Database.

Example

Insert into Legacy (A,B,C) Values ('0001',PCK(1234,2),PCK(5678,2))