今天在oracle12c数据库遇到的问题,下面重现一下:
1、先创建一个临时表 temp、一个数据表bitest_sum;
-- Create table create table PEC.BITEST_SUM ( yyyymm VARCHAR2(6), factno VARCHAR2(4), dept_no VARCHAR2(4), product VARCHAR2(6), amt NUMBER default 0 not null, amt_ys NUMBER default 0 not null ) tablespace BITBS; -- Add comments to the table comment on table PEC.BITEST_SUM is 'SUM结果测试'; -- Create/Recreate indexes create index PEC.BITEST_SUM_01 on PEC.BITEST_SUM (YYYYMM, FACTNO, DEPT_NO, PRODUCT) tablespace IDX_BI;
2、插入各维度数据到temp
DELETE FROM gt_temp; INSERT INTO gt_temp (main_code, v1 ) SELECT 'A','AA01' FROM dual; INSERT INTO gt_temp (main_code, v1 ) SELECT 'B',DEPT_NO FROM( select 'BB'||dbms_random.string('x',2) DEPT_NO from dual) CONNECT BY ROWNUM <= 1000; INSERT INTO gt_temp (main_code, v1 ) SELECT 'C', lpad(ROWNUM,6,'0') FROM dual CONNECT BY ROWNUM <=1000;
3、插入维度数据及随机值到结果表 bitest_sum
DECLARE CURSOR C1 IS SELECT v1 FROM pec.gt_temp WHERE main_code='A'; CURSOR C2 IS SELECT v1 FROM pec.gt_temp WHERE main_code='B'; CURSOR C3 IS SELECT v1 FROM pec.gt_temp WHERE main_code='C'; BEGIN FOR R1 IN C1 LOOP FOR R2 IN C2 LOOP FOR R3 IN C3 LOOP INSERT INTO BITEST_SUM SELECT '201605',a.v1,b.v1,c.v1, d.amt1,D.AMT2 FROM gt_temp a,gt_temp b,gt_temp c, (SELECT round(dbms_random.value(-10000,99999),2) amt1 ,round(dbms_random.value(-10000,99999),2) amt2 FROM dual) d WHERE a.main_code='A' AND A.V1=R1.V1 AND B.MAIN_CODE='B' AND B.V1=R2.V1 AND C.MAIN_CODE='C' AND C.V1=R3.V1; END LOOP; END LOOP; END LOOP; END; COMMIT;
4、检查数据结果
5、对结果数据进行update操作。提交之后再查询:
UPDATE pec.bitest_sum2 SET amt_ys=0 WHERE amt_ys<0 AND product LIKE '000%';
pass:加“group by 1”在sql中数据是对的,金额字段加nvl(amt,0)数据也是对的。
此问题已反馈给ORACLE,后续有结果再补充。