trunc function [message #518782] |
Sat, 06 August 2011 13:39 |
|
hassan08
Messages: 123 Registered: June 2011 Location: egypt
|
Senior Member |
|
|
i have problem when use trunc function
in form builder i have two cloumn
first column inserted data is 15.55
and i want the secound cloumn the will be too 15.55
i used this code but nothing happened
select sum(trunc(item_name,2)
into column2
from table_name
always the result be 16 i want it 15.55 without any round to this
value
|
|
|
|
|
Re: trunc function [message #518785 is a reply to message #518784] |
Sat, 06 August 2011 14:09 |
Solomon Yakobson
Messages: 3284 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
You should clearly understand when rounding occurs in SQL and PL/SQL from rounding that occurs in client tool. Rounding that occurs in SQL:
SQL> create table tbl1(n number(2))
2 /
Table created.
SQL> insert into tbl1 values(15.55)
2 /
1 row created.
SQL> select * from tbl1
2 /
N
----------
16
SQL>
And PL/SQL:
SQL> set serveroutput on
SQL> declare
2 n number(2);
3 begin
4 n := 15.55;
5 dbms_output.put_line(n);
6 end;
7 /
16
PL/SQL procedure successfully completed.
SQL>
But even if no rounding was done in SQL or PL/SQL, rounding can be done by client tool. For example SQL*Plus:
SQL> create table tbl1(n number)
2 /
Table created.
SQL> insert into tbl1 values(15.55)
2 /
1 row created.
SQL> select *
2 from tbl1
3 /
N
----------
15.55
SQL> column n format 99
SQL> select *
2 from tbl1
3 /
N
---
16
SQL> column n format 99999
SQL> select *
2 from tbl1
3 /
N
------
16
SQL> column n format 99999.9999
SQL> select *
2 from tbl1
3 /
N
-----------
15.5500
SQL> column n format 99999.99
SQL> select *
2 from tbl1
3 /
N
---------
15.55
SQL>
So it is clear from your post rounding occurs on client side - forms in your case. Check how corresponding form field is declared.
SY.
|
|
|