The semantics of comparing character columns of different types can lead to some confusion, so before I get into the main body of this note here’s a little test based on a table with one row:
create table t1(c2 char(2), c3 char(3), vc2 varchar2(2), vc3 varchar2(3)); insert into t1 values ('XX','XX','XX','XX'); commit; select count(*) c2_c3 from t1 where c2 = c3; select count(*) c2_vc3 from t1 where c2 = vc3; select count(*) c3_vc2 from t1 where c3 = vc2; select count(*) c3_vc3 from t1 where c3 = vc3;
I’ve inserted one row, using the same value for every single column; then I’ve been counting the row(s) where various pairs of columns match. Which (if any) of the four queries return the value 1 and which (if any) return the value zero ?