If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > right trim a decimal column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-02-07, 14:49
nivasreddy007 nivasreddy007 is offline
Registered User
 
Join Date: Jun 2007
Posts: 66
right trim a decimal column

I want to righttrim a column of decimal type by two decimal places in DB2.for example:: 3444.56788 to 3444.567 Please help me
Reply With Quote
  #2 (permalink)  
Old 08-02-07, 14:56
jsharon1248 jsharon1248 is offline
Registered User
 
Join Date: Apr 2007
Location: Chicago
Posts: 57
Try the truncate function:

truncate(col1,3)


truncates the column to 3 decimal positions
Reply With Quote
  #3 (permalink)  
Old 08-02-07, 15:53
nivasreddy007 nivasreddy007 is offline
Registered User
 
Join Date: Jun 2007
Posts: 66
Although i added the truncate function like::
Insert into table1(select truncate(sum(daytime),3) from table2) I am getting the following error.Please help.



SQL0413N Overflow occurred during numeric data type conversion.
SQLSTATE=22003
Reply With Quote
  #4 (permalink)  
Old 08-02-07, 16:20
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
Quote:
Originally Posted by nivasreddy007
I want to righttrim a column of decimal type by two decimal places in DB2.for example:: 3444.56788 to 3444.567 Please help me
use decimal(). for example, Decimal(3444.56788, 15,3)
Reply With Quote
  #5 (permalink)  
Old 08-02-07, 16:43
nivasreddy007 nivasreddy007 is offline
Registered User
 
Join Date: Jun 2007
Posts: 66
SQL0413N Overflow occurred during numeric data type conversion.
SQLSTATE=22003



I am getting the above error..Please help
Reply With Quote
  #6 (permalink)  
Old 08-02-07, 17:33
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
Quote:
Originally Posted by nivasreddy007
SQL0413N Overflow occurred during numeric data type conversion.
SQLSTATE=22003



I am getting the above error..Please help
try decimal(..., 31,3)
Reply With Quote
  #7 (permalink)  
Old 08-02-07, 19:30
nivasreddy007 nivasreddy007 is offline
Registered User
 
Join Date: Jun 2007
Posts: 66
Same error again.Overflow error again. Let me know if i can try anything different
Reply With Quote
  #8 (permalink)  
Old 08-03-07, 03:48
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You should post your table definition and your exact SQL statements here. The thing is that you can never run into an overflow if the source table is something like DECIMAL(31,5) and the target DECIMAL(31,3).
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #9 (permalink)  
Old 08-03-07, 10:01
jsharon1248 jsharon1248 is offline
Registered User
 
Join Date: Apr 2007
Location: Chicago
Posts: 57
I'll echo what Stolze said. We need the table definitions.

After playing around with the functions, the decimal function is a better option than the trunc function.

I suspect that the sum function is causing your problem. The sum is probably accumulating a value that's too large for the target column. Run the select by itself to see the value that you're trying to insert and then determine if that value will fit into the target column.
Reply With Quote
  #10 (permalink)  
Old 08-06-07, 16:41
nivasreddy007 nivasreddy007 is offline
Registered User
 
Join Date: Jun 2007
Posts: 66
My problem got resolved after i redefined the column as (31,3) instead of (8,4)


Thanks for ur ideas
Reply With Quote
  #11 (permalink)  
Old 08-07-07, 02:22
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,
but this was not the problem!

The value 3444.567 can be saved in DEC(8,4)! I suspect table definition is not DEC(8,4).

DEC(8,4) means:
Code:
3444.567
1234 567 -> 7 is enough. So 8 is OK.
DEC(8,4) means:
Code:
3444.567
     123 -> so 3 is enough. So 4 is OK
Defining a column dec(31,3) is not a good idea. To many disk space wasted. Stolce just gave you a hint to try it out and not to put in production environment.

Hope this helps,
Grofaty

Last edited by grofaty; 08-07-07 at 02:26.
Reply With Quote
  #12 (permalink)  
Old 08-07-07, 11:10
nivasreddy007 nivasreddy007 is offline
Registered User
 
Join Date: Jun 2007
Posts: 66
3444.567 is not the data that i am using.. I justed used it as an example.So, dont consider it as input data.I have a sum(cputime) in the select statement and the cputime is defined as decimal(8,4)..I believe some of the CPUTIME data value were very big. So I wanted it be 31,3 so that it will serve all the future needs
Reply With Quote
  #13 (permalink)  
Old 08-07-07, 11:44
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You may want to consider using BIGINT for your data. Just multiple the CPU time by 10000 (to get rid of the fractions), then you have a whole integer.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #14 (permalink)  
Old 08-07-07, 12:57
nivasreddy007 nivasreddy007 is offline
Registered User
 
Join Date: Jun 2007
Posts: 66
Thanks for your tips
Reply With Quote
  #15 (permalink)  
Old 08-07-07, 14:44
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
Quote:
Originally Posted by stolze
You may want to consider using BIGINT for your data. Just multiple the CPU time by 10000 (to get rid of the fractions), then you have a whole integer.
bigint is -9223372036854775808 to +9223372036854775807, and take 8 bytes.

decimal(31,) is 1 − 10łą to 10łą − 1. (31 bytes)?

And also decimal and integer use different rule for arith operations. decimal is more complex. But in some case, we have to use it. Without knowing what the application is used, I will stay with decimal.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On