我有一个查询,如下所示:
TRUNCATE TABLE DNARTLOAD;
COMMIT;
.... <Cursor here> .... <do something>.....
tmp_future_phaseA := substr(tmp_phases,1,1);
tmp_future_phaseB := substr(tmp_phases,2,1);
tmp_future_phaseC := substr(tmp_phases,3,1);
INSERT INTO DNARTLOAD (LOADNAME,KVARATING,PHASE,FULLPHASE) VALUES
(tmp_load_name, tmp_kvarating, tmp_future_phaseA, tmp_phase);
问题是查询每次都无法正确插入 tmp_phases。我正在做的是获取临时阶段的子字符串(从不为空)并将第一个、第二个和第三个字符分配给另一组 varchar 变量。分配它们后,我将数据插入到表中并提交。问题是它并不总是有效。它总是会用一个字符填充 tmp_future_phaseA、B 和 C,但是当我插入 tmp_phase 时,它有时会填充 null,有时会填充值。
示例数据:
tmp_phase = 'ABC'
tmp_futurephaseA = 'A'
tmp_futurephaseB = 'B'
tmp_futurephaseC = 'C'
有时我会得到以下信息:
A 'ABC'
B 'ABC'
C 'ABC'
在同一 plsql 中的其他时间,我将得到以下信息:
A NULL
B NULL
C NULL
编辑:添加问题:
LOOP
tmp_future_phaseA := NULL;
tmp_future_phaseB := NULL;
tmp_future_phaseC := NULL;
tmp_phases := NULL;
FETCH C3 INTO tmp_load_name, tmp_kvarating, tmp_phases;
EXIT WHEN C3%NOTFOUND;
IF LENGTH(tmp_phases) = 3 THEN
tmp_kvarating := tmp_kvarating / 3;
END IF;
IF LENGTH(tmp_phases) = 2 THEN
tmp_kvarating := tmp_kvarating /2;
END IF;
tmp_future_phaseA := substr(tmp_phases,1,1);
tmp_future_phaseB := substr(tmp_phases,2,1);
tmp_future_phaseC := substr(tmp_phases,3,1);
IF tmp_future_phaseA IS NOT NULL THEN
INSERT INTO DNARTLOAD (LOADNAME,KVARATING,PHASE) VALUES (tmp_load_name, tmp_kvarating, tmp_future_phaseA);
END IF;
IF tmp_future_phaseB IS NOT NULL THEN
INSERT INTO DNARTLOAD (LOADNAME,KVARATING,PHASE) VALUES (tmp_load_name, tmp_kvarating, tmp_future_phaseB);
END IF;
IF tmp_future_phaseC IS NOT NULL THEN
INSERT INTO DNARTLOAD (LOADNAME,KVARATING,PHASE) VALUES (tmp_load_name, tmp_kvarating, tmp_future_phaseC);
END IF;