DB2 - Problem description
| Problem IC91701 | Status: Closed |
VARCHAR RESULT DATA TYPE INSTEAD OF CHAR WITH VARCHAR2 ENABLED DATABASE | |
| product: | |
DB2 FOR LUW / DB2FORLUW / A10 - DB2 | |
| Problem description: | |
When doing a describe command on a select query, the result data
type in a VARCHAR2 enabled database may be VARCHAR instead of
the expected CHAR.
Example:
----------------------------------------------------------------
C:\>db2 create table test(c1 int)
DB20000I The SQL command completed successfully.
>> A) Output from the describe select command with the issue:
C:\>db2 "describe select 'Y' as flag1, case when 1 = 1 then 'Y'
else 'N' end as flag2 from test"
Column Information
Number of columns: 2
SQL type Type length Column name
Name
length
-------------------- -----------
------------------------------ -----------
452 CHARACTER 1 FLAG1
5
448 VARCHAR 1 FLAG2
5
>> B) Expected output :
C:\>db2 "describe select 'Y' as flag1, case when 1 = 1 then 'Y'
else 'N' end as flag2 from test"
Column Information
Number of columns: 2
SQL type Type length Column name
Name length
-------------------- -----------
------------------------------ -----------
452 CHARACTER 1 FLAG1
5
452 CHARACTER 1 FLAG2
5
The effects of setting the varchar2_compat database
configuration parameter to ON are as follows.
Rules for result data types involving character strings are
modified as follows:
If one operand is... And the other operand is... The
data type
of the result is...
CHAR(x) CHAR(x) CHAR(x)
CHAR(x) CHAR(y) VARCHAR(z) where z = max(x,y)
Rules for result data types involving graphic strings are
modified as follows:
If one operand is... And the other operand is... The
data type
of the result is...
GRAPHIC(x) GRAPHIC(x) GRAPHIC(x)
GRAPHIC(x) GRAPHIC(y) VARGRAPHIC(z) where z = max(x,y)
Rules for result data types involving character and graphic
strings are modified as follows:
If one operand is... And the other operand is... The
data type
of the result is...
GRAPHIC(x) CHAR(y) VARGRAPHIC(z) where z = max(x,y)
The functions that return character string arguments, or that
are based on parameters with character string data types, also
treat empty string CHAR, NCHAR, VARCHAR, or NVARCHAR values as
null values. Special considerations apply for some functions
when the varchar2_compat database configuration parameter is set
to ON, and these are listed here.
DECODE: If the first result expression is an untyped null it
is assumed to be VARCHAR(0). If the first result expression is
CHAR or GRAPHIC, it is promoted to VARCHAR or VARGRAPHIC.
GREATEST: If the first expression is CHAR or GRAPHIC, it is
promoted to VARCHAR or VARGRAPHIC.
LEAST: If the first expression is CHAR or GRAPHIC, it is
promoted to VARCHAR or VARGRAPHIC.
NVL: If the first expression is CHAR or GRAPHIC, it is
promoted to VARCHAR or VARGRAPHIC.
NVL2: If the result expression is an untyped null it is
assumed to be VARCHAR(0). If the result expression is CHAR or
GRAPHIC, it is promoted to VARCHAR or VARGRAPHIC. | |
| Problem Summary: | |
| Local Fix: | |
Cast the final result to CHAR(N) | |
| Solution | |
| Workaround | |
not known / see Local fix | |
| Comment | |
Fix planned for v10fp2 | |
| Timestamps | |
Date - problem reported : Date - problem closed : Date - last modified : | 21.04.2013 04.06.2013 17.06.2013 |
| Problem solved at the following versions (IBM BugInfos) | |
| Problem solved according to the fixlist(s) of the following version(s) | |