PHP OCI,Oracle和默认数字格式 [英] PHP OCI, Oracle, and default number format

查看:155
本文介绍了PHP OCI,Oracle和默认数字格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用PHP OCI从Oracle数据库执行提取时,小于1的数字显示为 .XXXXXX,例如 0.249999 。有没有办法将它设置为 0.XXXXXX 或任何其他格式,而不修改每个查询使用 to_char()

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?)

推荐答案

有没有办法做你的要求在全球范围短修改的PHP / oci-extension源代码。这种行为的原因是因为oracle oci在结果中省略了0,并且php根据列数据类型将所有结果从oci转换为字符串而不执行任何转换。甚至结果在SQL * Plus默认省略0,和SQL * Plus格式必须与设置numformat 来定制列格式和前置0被调用。

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.

最常见的解决方法是使用来包裹你的查询和检查数值列与 is_numeric ,然后用 number_format 或<$ C画幅的数字列值$ C>的sprintf 。希望您的应用程序已经使用股票php oci函数的包装,所以你可以在一个位置进行更改。

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.

这篇关于PHP OCI,Oracle和默认数字格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆