我有这个程序:
create or replace PROCEDURE CONVERTE
IS
CURSOR oldemployees IS
SELECT *
FROM emp1
WHERE data_saida= NULL;
new_ndep emp1.num_dep%type;
bi_inexistente EXCEPTION;
dep_inexistente EXCEPTION;
employeeNr emp1.num_empregado%type;
BEGIN
FOR old_emp IN oldemployees
LOOP
employeeNr:= old_emp.num_empregado;
if (old_emp.bi = NULL) then
raise bi_inexistente;
else
IF (old_emp.num_dep>20) THEN
SELECT ndep_novo INTO new_ndep FROM Converte_dep WHERE ndep_antigo= old_emp.num_dep;
elsif (old_emp.num_dep = NULL) then
new_ndep:= 0;
raise dep_inexistente;
end if;
INSERT INTO EMP2 VALUES (old_emp.bi, old_emp.nome, old_emp.morada, old_emp.data_entrada, old_emp.data_saida, new_ndep);
COMMIT;
end if;
end loop;
EXCEPTION
when bi_inexistente then
INSERT INTO ERROS VALUES(employeeNr, 'BI Inexistente');
COMMIT;
when dep_inexistente then
INSERT INTO ERROS VALUES(employeeNr, 'Departamento Inexistente');
COMMIT;
end;
我想做 INSERT INTO EMP2 VALUES (old_emp.bi, old_emp.nome, old_emp.morada, old_emp.data_entrada, old_emp.data_saida, new_ndep);即使在提高dep_inexistente之后,但是在阅读了oracle的参考之后,我还是有点困惑;基本上,当它为空时,我不想插入,否则我想插入,即使部门号为空(我转为 0)。
那么,代码是否正确,或者我应该如何引发我的异常或为我的案例处理预定义的异常?