Convert numbers and strings
Before HCL OneDB™ ESQL/C can convert a value from one data type to another, it must determine whether the conversion is meaningful.
The following table shows possible
conversions between numeric data types and character data types. In
this figure, N
represents a value with a numeric
data type (such as DECIMAL, FLOAT, or SMALLINT) and C
represents
a value with a character data type (such as CHAR or VARCHAR).
Conversion | Problem | Results |
---|---|---|
C C | Does not fit | HCL
OneDB ESQL/C truncates
the string, sets a warning (sqlca.sqlwarn.sqlwarn1 to W and
SQLSTATE to 01004 ), and sets any indicator variable
to the size of the original string. |
N C | None | HCL OneDB ESQL/C creates a string for the numeric value; it uses an exponential format for large or small numbers. |
N C | Does not fit | HCL
OneDB ESQL/C fills
the string with asterisks, sets a warning (sqlca.sqlwarn.sqlwarn1 to W and
SQLSTATE to 01004 ), and sets any indicator variable
to a positive integer.When the fractional part of a number does not fit in a character variable, HCL OneDB ESQL/C rounds the number. Asterisks are displayed only when the integer part does not fit. |
C N | None | HCL OneDB ESQL/C determines the numeric data type based on the format of the character value; if the character contains a decimal point, HCL OneDB ESQL/C converts the value to a DECIMAL value. |
C N | Not a number | The number is undefined; HCL OneDB ESQL/C sets sqlca.sqlcode and SQLSTATE to indicate a runtime error. |
C N | Overflow | The number is undefined; HCL OneDB ESQL/C sets sqlca.sqlcode and SQLSTATE to indicate a runtime error. |
N N | Does not fit | HCL
OneDB ESQL/C attempts
to convert the number to the new data type. For information about possible errors, see the HCL OneDB Guide to SQL: Reference. |
N N | Overflow | The number is undefined; HCL OneDB ESQL/C sets sqlca.sqlcode and SQLSTATE to indicate a runtime error. |
In Data conversion problems and results, the phrase Does not fit means that the size of the data from the source variable or column exceeds the size of the target column or variable.