[英]spool truncates decimal data
I'm doing a quite easy query (sum a column): 我正在做一个很简单的查询(求和一列):
select
SUM (txn.amt_val) AS monto
from siebel.s_loy_txn txn
The query result is 791412524.16 but when I do a spool, the result I get is truncated. 查询结果为791412524.16,但是当我执行假脱机操作时,我得到的结果将被截断。
So: 791412524 因此:791412524
The full query is something like this --> 完整的查询是这样的->
SET serveroutput ON SIZE 1000000;
SET pages 0;
SET linesize 15000;
SET heading OFF;
SET verify OFF;
SET echo OFF;
SET feedback OFF;
SET term OFF;
SET trims ON;
Spool 'C:\Users\Report.txt' --spoolname from dual;
Select
SUM (txn.amt_val) AS monto
from siebel.s_loy_txn txn;
SPOOL off
也许明确地将数字转换为足够长的char?
select cast(txn.amt_val as char(20)) as monto from siebel.s_loy_txn txn;
The default numwidth
in SQL*Plus is 10. In combination with the default numformat
means it shows up to ten significant digits for a decimal value; SQL * Plus中的默认
numwidth
为10。与默认numformat
组合使用意味着它最多可以显示十位十进制有效数字。 it's implicitly rounding the decimal up in this case, rather than truncating. 在这种情况下,它隐式地将小数点四舍五入,而不是截断。 If your result was 91412524.16 you would see 91412524.2.
如果结果为91412524.16,则会看到91412524.2。
This is described in the documentation : 在文档中对此进行了描述:
SQL*Plus normally displays numbers with as many digits as are required for accuracy, up to a standard display width determined by the value of the NUMWIDTH variable of the SET command (normally 10).
SQL * Plus通常显示的数字与精度所需的位数一样多,最大显示标准宽度由SET命令的NUMWIDTH变量的值确定(通常为10)。 If a number is larger than the value of SET NUMWIDTH, SQL*Plus rounds the number up or down to the maximum number of characters allowed if possible, or displays hashes if the number is too large.
如果数字大于SET NUMWIDTH的值,则SQL * Plus会在可能的情况下将数字向上或向下四舍五入到允许的最大字符数,如果数字太大则显示哈希。
... though that isn't particularly clear. ...虽然还不是很清楚。
You can just make numwidth
larger, to at least 12 in this case; 您可以将
numwidth
增大,在这种情况下至少应为12。 or set numformat
to explicitly include decimals (optionally with fm
to suppress leading blanks and trailing zeros),; 或将
numformat
设置为显式包括小数(可选地,使用fm
来抑制前导空格和尾随零), or use to_char()
with a similar mask; 或者使用具有类似掩码的
to_char()
; or as CZ Zhu suggested you can cast which has the same effect but is less obvious. 或如朱哲Z(CZ Zhu)所建议的那样,您可以投射具有相同效果但不太明显的效果。
Testing all those options: 测试所有这些选项:
-- default numwidth and numformat
select 791412524.16 from dual;
set numwidth 11
select 791412524.16 from dual;
set numwidth 12
select 791412524.16 from dual;
set numwidth 10
set numformat fm999999999999999.99999
select 791412524.16 from dual;
set numformat ""
select to_char(791412524.16, 'fm999999999999999.99999') from dual;
select cast(791412524.16 as varchar2(20)) from dual;
Which gets: 得到:
791412524
791412524.2
791412524.16
791412524.16
791412524.16
791412524.16
The question is tagged for SQL Developer, but as the pagesize you're using errors in that, you seem to be using SQL*Plus. 这个问题是为SQL Developer标记的,但是由于您使用的页面大小是错误的,因此您似乎正在使用SQL * Plus。 The same thing does apply to SQL Developer too, except its default
numformat
is less friendly, giving you 7.9E+08
. 同样的事情也适用于SQL Developer,除了它的默认
numformat
不那么友好,给您7.9E+08
。 Changing numwidth
doesn't help, but the other versions get the full value in SQL Developer too. 更改
numwidth
并没有帮助,但是其他版本在SQL Developer中也获得了全部价值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.