Wrong Results When Using Inlist And Comparing Char And Varchar2

(Doc ID 1566476.1)

Last updated on AUGUST 13, 2013

Applies to:

Oracle Database - Enterprise Edition - Version 11.2.0.3 and later
Information in this document applies to any platform.

Symptoms

Combination of join predicate with CHAR and VARCHAR operands and inlist predicate with the same CHAR operand can cause wrong result

Example Scenario:

CREATE TABLE djw ( A char(4) , B date ) ;
create index djw_ind on djw(B,A) ;

INSERT INTO djw VALUES ('A' ,sysdate ) ;
INSERT INTO djw VALUES ('AA',SYSDATE ) ;
INSERT INTO djw VALUES ('AAA' ,SYSDATE) ;

CREATE TABLE djw2 ( A varchar2(4) ) ;

INSERT INTO djw2 VALUES ('A' ) ;
INSERT INTO djw2 VALUES ('AA' ) ;
INSERT INTO djw2 VALUES ('AAA' ) ;
INSERT INTO djw2 VALUES ('AAAA' ) ;

commit ;

When the following queries are executed:


SELECT count(*) FROM djw, djw2 WHERE djw.A = rpad(djw2.A,4) AND djw.A IN ('A','AAAA') AND djw.b > SYSDATE -1
returns 1 row
SELECT count(*) FROM djw, djw2 WHERE djw.A = rpad(djw2.A,4) AND djw.A IN ('AAAA','A') AND djw.b > SYSDATE -1
returns 0  row

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms