Comparing VARCHAR2 and CHAR Columns Equality Test

From: Larry Nudelman <LNudelm_at_unotes1.mnet.uswest.com>
Date: 1995/08/31
Message-ID: <4253rl$mqs_at_engineer.mrg.uswest.com>#1/1


Somewhere I saw a solution to this, but...

An application developer is comparing (equality) two columns, one is VARCHAR2 and the other CHAR.

Table A

	chr1        CHAR(100),
	Var2        VARCHAR2(100)

Insert into A Values ('ABC', 'ABC');
Insert into A Values ('ABCD', 'ABC');
Select * from A where chr1 = Var2;
This Returns no rows since Oracle Consideres a comparision with a VARCHAR2 as a non-padded compare, thus chr1 is > than Var2.

The developer got around the problem by using: Select * from A where RTRIM(chr1) = Var2; This Returns the 'ABC' row, but since a chr1 is in a function, a full table scan is done. (If you tell me that there are only two rows in the table so a full table scan does not make any difference, you missed my point).

I remember seeing a swift way to avoid using a function, it was something like:
Select * from A where chr1 between Var2 and Chr1; This returns both the ABC and ABCD columns.

Is there a way to complete the comparision i.e. return just ABC row without using a function that will negate an index on the column.

Thanks,
Larry Nudelman Oracle DBA,
U S WEST MIS Received on Thu Aug 31 1995 - 00:00:00 CEST

Original text of this message