Because Oracle converts a string literal to CHAR; since CHAR has a fixed length, it must expand the shorter string to the correct length and therefore add spaces. Try instead of VARCHAR2:
SELECT CASE WHEN cast(' 1a' as varchar2(100)) = cast(' 1a ' as varchar2(100)) THEN 'EQUAL - but it isn´t- HELP!!!!' ELSE 'UNEQUAL' END from dual;
EDIT: example to illustrate the difference between CHAR (10) and VARCHAR2 (10)
declare l_char1 char(10) := '1'; l_char2 char(10) := '1 '; l_varchar1 varchar2(10) := '1'; l_varchar2 varchar2(10) := '1 '; begin if l_char1 = l_char2 then dbms_output.put_line('char equal'); else dbms_output.put_line('char NOT equal'); end if; if l_varchar1 = l_varchar2 then dbms_output.put_line('varchar equal'); else dbms_output.put_line('varchar NOT equal'); end if; end;
Frank schmitt
source share