我的db2版本是9.5:
我有一个选择查询,如下所示:
select sum(BAL_BOOK_AMT) as sum from mySchema.myTable group by idCol
结果如下:
SUM
---------
0
2,475,000
746,966.091
-627,247.63
我想使用此查询,如下所示:
insert into mySchema.myTable1 select sum(bal_book_amt) as sum from mySchema.myTable group by idCol
但是,mySchema.myTable1中的SUM列的类型为VARCHAR(40)(由于其他原因,我无法将其更改为十进制)。因为我得到了以下错误:
by: com.ibm.db2.jcc.b.nm: DB2 SQL Error: SQLCODE=-408, SQLSTATE=42821
当我尝试以下操作时:
select char(sum(BAL_BOOK_AMT)) as sum from mySchema.myTable group by idCol
值变为:
00000000000000000000000000000.00
00000000000000000000000000000.00
00000000000000000000002475000.00
00000000000000000000000550000.00
00000000000000000000000746966.09
我不想要。
如何进行格式化以使值按字符串形式出现:
0
2,475,000
746,966.091
-627,247.63
感谢阅读!
答案 0 :(得分:0)
insert into mySchema.myTable1
select VARCHAR_FORMAT(sum(bal_book_amt), '999,999,999,999.99') as sum
....