The varchar data type
The varchar data type is the data type that holds character data of varying lengths.
When an application reads a value from a CHAR column into a host variable of type varchar, preserves any trailing blanks and terminates the array with a null character. The behavior is the same if an application reads a value from a VARCHAR column into a host variable of the varchar data type.
EXEC SQL BEGIN DECLARE SECTION;
varchar varc_name[n + 1];
EXEC SQL END DECLARE SECTION;
VARCHAR size macros
Name of Macro | Description |
---|---|
MAXVCLEN | The maximum number of characters that you can store in a VARCHAR column. This value is 255. |
VCLENGTH(s) | The length to declare the host variable. |
VCMIN(s) | The minimum number of characters that you can store in the VARCHAR column. Can range from 1 to 255 bytes but must be smaller than the maximum size of the VARCHAR. |
VCMAX(s) | The maximum number of characters that you can store in the VARCHAR column. Can range from 1 to 255 bytes. |
VCSIZ(min, max) | The encoded size value, based on min and max, for the VARCHAR column. |
These macros are useful when your program uses dynamic SQL. After a DESCRIBE statement, the macros can manipulate size information that the database server stores in the LENGTH field of the system-descriptor area (or the sqllen field of the sqlda structure). Your database server stores size information for a VARCHAR column in the syscolumns system catalog table.
The varchar.ec demonstration program
When the IFX_PAD_VARCHAR environment variable is set to 1, the client sends the VARCHAR data type with padded trailing spaces. When this environment is not set (the default), the client sends the VARCHAR data type value without trailing spaces. The IFX_PAD_VARCHAR environment variable must be set only at the client side and is supported only with Version 9.53 and 2.90 or later and HCL OneDB Version 9.40 or later.