Insert VARCHAR data
When an application inserts a value from a char, varchar, lvarchar, or string host variable into a VARCHAR column, also inserts any trailing blanks. does not, however, add trailing blanks.
-1279: Value exceeds string column length.
Although char, varchar, lvarchar, and string host variables contain null terminators, never inserts these characters into a database column. (Host variables of type fixchar must never contain null characters.) If an application inserts a char, varchar, lvarchar, or string value into a VARCHAR column, the database server tracks the end of the value internally.
Source type | Destination type | Result |
---|---|---|
char | VARCHAR | If the source is longer than the max VARCHAR, truncate the value and set the indicator variable. If the max VARCHAR is longer than the source, the length of the destination equals the length of the source (not including the null terminator of the source). |
fixchar | VARCHAR | If the source is longer than the max VARCHAR, truncate the value and set the indicator variable. If the max VARCHAR is longer than the source, the length of the destination equals the length of the source. |
string | VARCHAR | If the source is longer than the max VARCHAR, truncate the value and set the indicator variable. If the max VARCHAR is longer than the source, the length of the destination equals the length of the source (not including the null terminator of the source). |
lvarchar | VARCHAR | If the source is longer than the max VARCHAR, truncate the value and set the indicator variable. If the max VARCHAR is longer than the source, the length of the destination equals the length of the source. |
If you use the locale-sensitive character data type, NVARCHAR, you can insert a value from a character host variable into an NVARCHAR column. Insertion into NVARCHAR columns follows the same behavior as insertion into VARCHAR columns. For more information about how to declare host variables for the NVARCHAR data type, see the HCL OneDB™ GLS User's Guide.
Source Type | Contents | Length | Destination type | Contents | Length |
---|---|---|---|---|---|
char(10) | Fairfield\0 | 10 | VARCHAR(4) | Fair | 4 |
char(10) | Fairfield\0 | 10 | VARCHAR(11) | Fairfield | 9 |
char(12) | Fairfield++\0 | 12 | VARCHAR(9) | Fairfield | 9 |
char(13) | Fairfield+++\0 | 13 | VARCHAR(6) | Fairfi | 6 |
char(11) | Fairfield+\0 | 11 | VARCHAR(11) | Fairfield+ | 10 |
fixchar(9) | Fairfield | 9 | VARCHAR(3) | Fai | 3 |
fixchar(9) | Fairfield | 9 | VARCHAR(11) | Fairfield | 9 |
fixchar(11) | Fairfield++ | 11 | VARCHAR(9) | Fairfield | 9 |
fixchar(13) | Fairfield++++ | 13 | VARCHAR(7) | Fairfie | 7 |
fixchar(10) | Fairfield+ | 10 | VARCHAR(12) | Fairfield+ | 10 |
string(9) | Fairfield\0 | 9 | VARCHAR(4) | Fair | 4 |
string(9) | Fairfield\0 | 9 | VARCHAR(11) | Fairfield | 9 |