PHP OCI, Oracle, and default number format

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 11:43:09

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.

Using PHP you can easily add the 0, by converting to float:

$a = '.249999';
echo (float) $a;

Meaning you can convert your number by

$row['number'] = (float) $row['number'];

after fetching it from the DB.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!