PACKED( ) function
Syntax
PACKED(number, length_of_result)
Parameters
Name | Type | Description |
---|---|---|
number |
numeric |
The numeric value or field to convert. |
length_of_result | numeric |
The number of bytes to use in the output string. |
Output
Numeric.
Examples
Basic examples
Integer and decimal input
Returns 00075C:
PACKED(75, 3)
PACKED(7.5, 3)
Truncated digits in output
Returns 00000012456D:
PACKED(-12.456, 6)
Returns 456D:
PACKED(-12.456, 2)
Advanced examples
Creating an 8-byte field to update a mainframe
You need to create an 8-byte field containing each employee's salary as a PACKED number for uploading to a mainframe:
EXTRACT PACKED(SALARY, 8) AS "Salary_Export" TO "export"
Remarks
What is Packed data?
The Packed data type is used by mainframe operating systems to store numeric values in a format that uses minimal storage space. The Packed data type stores two digits in each byte, and the last byte indicates whether the value is positive or negative.
When to use PACKED( )
Use the PACKED( ) function to convert numeric data to the Packed format for export to mainframe systems.
Truncated return values
If the length_of_result value is shorter than the length of the number value, the additional digits are truncated.