【发布时间】:2013-12-27 11:45:27
【问题描述】:
在创建以下触发器后尝试插入表时,我收到 ORA-01403 no data found 错误:
CREATE OR REPLACE TRIGGER unic_disc
BEFORE insert ON disciplina
FOR EACH ROW
DECLARE
CURSOR cursor_professor IS
SELECT matricula_professor
FROM disciplina;
temp_prof disciplina.matricula_professor%type;
BEGIN
OPEN cursor_professor;
FETCH cursor_professor INTO temp_prof;
CLOSE cursor_professor;
END;
/
(变量是葡萄牙语,但它们的名称不会影响逻辑。) 表创建,
CREATE TABLE disciplina (
codigo_disciplina NUMBER,
ementa VARCHAR2(50) NOT NULL,
conteudo_programatico VARCHAR2(100) NOT NULL,
matricula_professor NUMBER NOT NULL,
CONSTRAINT disciplina_pk PRIMARY KEY (codigo_disciplina),
CONSTRAINT disciplina_matricula_prof_fk FOREIGN KEY (matricula_professor) REFERENCES professor (matricula_professor)
);
我的插入查询:
INSERT INTO disciplina (codigo_disciplina,ementa,conteudo_programatico,matricula_professor) VALUES (7,'E6', 'C6',7777);
编辑:我认为错误是因为我从正在编辑的同一个表中进行选择。
【问题讨论】:
-
桌上还有其他触发器吗?
-
您确定要以这种方式使用光标而不是对其进行迭代吗?
-
还有其他触发器,而我实际使用的触发器更复杂,为了查找错误,我对其进行了简化。在实际的触发器中,我遍历光标。