Oracle10 and JDBC: how to make CHAR ignore trailing spaces at comparision? Oracle10 and JDBC: how to make CHAR ignore trailing spaces at comparision? oracle oracle

Oracle10 and JDBC: how to make CHAR ignore trailing spaces at comparision?


Note that Oracle compares CHAR values using blank-padded comparison semantics.

From Datatype Comparison Rules,

Oracle uses blank-padded comparison semantics only when both values in the comparison are either expressions of datatype CHAR, NCHAR, text literals, or values returned by the USER function.

In your example, is 'ONT' passed as a bind parameter, or is it built into the query textually, as you illustrated? If a bind parameter, then make sure that it is bound as type CHAR. Otherwise, verify the client library version used, as really old versions of Oracle (e.g. v6) will have different comparison semantics for CHAR.


If you cannot change your database table, you can modify your query.

Some alternatives for RTRIM:

.. WHERE PRT_STATUS like 'ONT%' ...

.. WHERE PRT_STATUS = 'ONT ' ... -- 2 white spaces behind T

.. WHERE PRT_STATUS = rpad('ONT',5,' ') ...


I would change CHAR(5) column into varchar2(5) in db.