我有这两个表:
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
。数值存储为数字数据类型。我在这里缺少什么?
答案 0 :(得分:0)
SELECT SYSDATE ,A.P4, B.P4, A.P4-B.P4
FROM TAB_A A,TAB_B B
WHERE A.MYDATE=B.MYDATE
确保p4值符合您的预期......
答案 1 :(得分: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)