IBM Support

IT21760: DB2 MAY RETURN WRONG RESULTS WITH ORACLE COMPATIBILITY AND SUBSTR

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • DB2 may return wrong results when all the following conditions
    are met:
    -The database has oracle compatibility
    (DB2_COMPATIBILITY_VECTOR=ORA) mode enabled.
    -The SELECT query being issued contains a relational operator
    predicate with SUBSTR.
    -The string argument to SUBSTR is from a table that has an index
    on that column.
    -The other operand of the relational operator is a literal.
    
    This forces the optimizer to perform an index scan using only
    the
    start/stop predicates. The index scan LOLEPOP does not contain
    the SUBSTR predicate, only the start/stop preds.
    
    Example:
    
    create table t (v VARCHAR(128));
    create index i on t(v);
    insert into t values 'PT1', 'PT10';
    
    select v from t where substr(v, 1, 20) = cast('PT1' as
    VARCHAR(20));
    
    The above query returns two rows ('PT1', 'PT10') when we should
    only
    be returning one ('PT1').
    
    The expected result (one row) is returned by the following:
    
    select v from t where v = cast('PT1' as VARCHAR(20));
    

Local fix

  • Workaround:
    
    Replace the literal with a table column or variable.
    Continuing with the example above:
    
    create variable myvar char(3) default 'PT1';
    select * from test where substr(v, 1, 20) = myvar;
    

Problem summary

  • ****************************************************************
    * USERS AFFECTED:                                              *
    * Compatibility ORA users                                      *
    ****************************************************************
    * PROBLEM DESCRIPTION:                                         *
    * See Error Description                                        *
    ****************************************************************
    * RECOMMENDATION:                                              *
    * See Error Description. Please, install fix.                  *
    ****************************************************************
    

Problem conclusion

  • See Error Description. Please, install fix.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IT21760

  • Reported component name

    DB2 FOR LUW

  • Reported component ID

    DB2FORLUW

  • Reported release

    A50

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    YesHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2017-08-03

  • Closed date

    2017-09-27

  • Last modified date

    2017-10-12

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

    IT21945 IT21946 IT21948

Fix information

  • Fixed component name

    DB2 FOR LUW

  • Fixed component ID

    DB2FORLUW

Applicable component levels

  • RA50 PSN

       UP

[{"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSEPGG","label":"DB2 for Linux, UNIX and Windows"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"10.5","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
12 October 2017