Skip to content
Advertisement

Oracle chr() diferent returns from SQL engine versus PL/SQL engine, why?

Same function, same argument, different outputs:

PL/SQL procedure successfully completed.

Advertisement

Answer

In your case, chr() appears to be performing an implicit conversion to binary_float (IEEE 754 floating-point representation) as the datatype, as opposed to number (ANSI SQL NUMERIC). This results in different rounding results. I cannot duplicate your results on 19c unless I force the datatype, in which case I get the same results you do:

with output:

When using binary_double or binary_float, the chr() function implicitly rounds the value of n up in PL/SQL. In all cases of SQL, or when using number in PL/SQL, chr() truncates the decimal portion of the number, effectively rounding down.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement