When I execute a fetch from an Oracle database using PHP OCI, numbers that are less than 1 are shown as .XXXXXX,
e.g. .249999
. Is there a way to set this to 0.XXXXXX
or to any other format, without modifying every query to use to_char()
explicitly? (Perhaps through some session parameters?)
There is no way to do what you're asking globally short of modifying php/oci-extension source code. The reason for this behavior is because oracle oci omits 0s in results and php converts all results from oci to strings without performing any casting depending on column datatype. Even results in SQL*Plus omit 0 by default, and SQL*Plus formatting has to be invoked with set numformat
to customize column formatting and prepend 0s.
There is currently no alter session parameter you can set to change this behavior.
Most common way to work around this is to use a wrapper around your queries and check for numeric columns with is_numeric
and then format the numeric column values with number_format
or sprintf
. Hopefully your application already uses a wrapper around stock php oci functions so you can make the change in one location.