Home » Developer & Programmer » Forms » trunc function
trunc function [message #518782] Sat, 06 August 2011 13:39 Go to next message
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 #518783 is a reply to message #518782] Sat, 06 August 2011 13:44 Go to previous messageGo to next message
Michel Cadot
Messages: 68675
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
i used this code but nothing happened

You should have an error as it is syntaxically incorrect.

Quote:
always the result be 16 i want it 15.55 without any round to this
value

So do it correctly.
What do you expect from us with what you posted, that is NOTHING.
I showed you how to post in your last topic.
Do it in the same way.

In short, read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version, with 4 decimals.

Use SQL*Plus and copy and paste your session, the WHOLE session.

Regards
Michel
Re: trunc function [message #518784 is a reply to message #518783] Sat, 06 August 2011 13:51 Go to previous messageGo to next message
hassan08
Messages: 123
Registered: June 2011
Location: egypt
Senior Member
i try the code in the sql and working right but when try it in form builder not working can attach the form ?
Re: trunc function [message #518785 is a reply to message #518784] Sat, 06 August 2011 14:09 Go to previous message
Solomon Yakobson
Messages: 3280
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.
Previous Topic: how to delete record when saved through post keywords
Next Topic: frm 40403 - calling form has not implemented changes
Goto Forum:
  


Current Time: Sun Sep 08 23:00:55 CDT 2024