0

我有这两张表:

SQL> SELECT * FROM TAB_A;
MYDATE        P4         D1      D2      P5      P6
--------- ---------- ---------- ----------- ----------- -----------
30-OCT-12    949,324  4,437,654  10,203,116  25,303,632  13,900,078


SQL> SELECT * FROM TAB_B;
MYDATE        P4         D1      D2      P5      P6
--------- ---------- ---------- ----------- ----------- -----------
30-OCT-12    937,796  4,388,477  10,091,811  25,028,402  13,755,882

我需要减去它们各自的列并将结果存储到第三个表中,如下所示:

SQL> INSERT INTO TAB_C (MYDATE, P4) SELECT SYSDATE,A.P4-B.P4 FROM  TAB_A A,TAB_B B WHERE A.MYDATE=B.MYDATE;

SQL> SELECT * FROM TAB_C;
MYDATE        P4         D1      D2      P5      P6
--------- ---------- ---------- ----------- ----------- -----------
30-OCT-12     926,268

结果是错误的。基础数学:949324-937796=11528. 数值存储为数字数据类型。我在这里想念什么?

4

2 回答 2

0

尝试这个:

INSERT INTO TAB_C (MYDATE, P4)
VALUES (SYSDATE, SELECT (A.P4-B.P4) FROM  TAB_A A, TAB_B B WHERE A.MYDATE=B.MYDATE)
于 2012-10-31T04:59:06.430 回答
0
SELECT SYSDATE ,A.P4, B.P4, A.P4-B.P4 
FROM  TAB_A A,TAB_B B 
WHERE A.MYDATE=B.MYDATE

确保 p4 值是您所期望的...

于 2012-10-31T00:06:46.743 回答