因为 Oracle 将您的字符串文字转换为 CHAR;由于 CHAR 是固定长度的,它必须将较短的字符串扩展为正确的长度,因此会添加空格。尝试 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;
编辑:示例说明 CHAR(10) 和 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;