postgresqldatabase-migrationora2pg

Oracle to_char numeric masking to postgres


I'm porting a procedure from Oracle to Postgres. In select of a query, I have TO_CHAR(v_numeric, '990.000')

It seems, the same TO_CHAR(v_numeric, '990.000') works in Postgres with same result.

Can someone please explain what the '990.000' in the query does?

TO_CHAR(123.4, '990.000') returns 123.400 in both Oracle and Postgres. Whereas TO_CHAR(1234.400, '990.000') returns ######## in Oracle and ###.### in Postgres. Does this ######## and ###.### hold the same numeric value which is inputted?


Solution

  • to_char is a function to format a number as string for output. The PostgreSQL function is there expressly for Oracle compatibility, but it is not totally compatible, as you see.

    The format 990.000 means that there will be one to three digits before the decimal point and three digits after it. 9 means that a value of 0 in that position will result in a blank rather than a 0.

    The # characters signify that the number cannot be represented in that format. The reason is that there are more than three digits before the decimal point.

    The resulting string does not "hold" a number, it is the rendering of a number as a string. It doesn't hold anything but the characters it consists of.