Same function, same argument, different outputs:
set serveroutput on;
declare
n number := 122.5;
c_plsql varchar2(1);
c_sql varchar2(1);
begin
c_plsql := chr(n);
select chr(n) into c_sql from dual;
dbms_output.put_line(c_plsql || ' ' || c_sql);
end;
/
{ z
PL/SQL procedure successfully completed.
In your case, chr() appears to be performing an implicit conversion to
binary_float(IEEE 754 floating-point representation) as the datatype, as opposed tonumber(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
nup in PL/SQL. In all cases of SQL, or when usingnumberin PL/SQL, chr() truncates the decimal portion of the number, effectively rounding down.