我在oracle SQL开发人员身上遇到此错误
create table loan_audit (
employee_id number not null,
tool_no number not null,
tool_out_date date not null,
due_date date not null);
这是我创建的触发器
CREATE OR REPLACE TRIGGER loan_audit_trigger
AFTER INSERT OR UPDATE OR DELETE
ON loan_02
FOR EACH ROW
BEGIN
IF INSERTING THEN
INSERT INTO loan_audit VALUES
(:new.employee_id, :new.tool_no, :new.tool_out_date, :new.due_date, 'INSERTED', SYSDATE);
ELSIF UPDATING THEN
INSERT INTO loan_audit VALUES
(:old.employee_id, :old.tool_no, :old.tool_out_date, :old.due_date, 'UPDATED', SYSDATE);
ELSIF DELETING THEN
INSERT INTO loan_audit VALUES
(:old.employee_id, :old.tool_no, :old.tool_out_date, :old.due_date, 'DELETED', SYSDATE);
END IF;
END;
我收到这些错误
Error(2,5): PL/SQL: SQL Statement ignored
Error(2,17): PL/SQL: ORA-00913: too many values
Error(5,5): PL/SQL: SQL Statement ignored
Error(5,17): PL/SQL: ORA-00913: too many values
Error(8,5): PL/SQL: SQL Statement ignored
Error(8,17): PL/SQL: ORA-00913: too many values
我在做错了什么?我一直试图让这个工作,但继续得到这个错误!在此先感谢您的所有帮助。
答案 0 :(得分:0)
在任何insert
列出明确的列:
IF INSERTING THEN
INSERT INTO loan_audit (employee_id, tool_no, tool_out_date, due_date)
VALUES ( :new.tool_no, :new.tool_out_date, :new.due_date );
ELSIF UPDATING THEN
INSERT INTO loan_audit (employee_id, tool_no, tool_out_date, due_date)
VALUES ( :old.tool_no, :old.tool_out_date, :old.due_date );
ELSIF DELETING THEN
INSERT INTO loan_audit (employee_id, tool_no, tool_out_date, due_date)
VALUES ( :old.tool_no, :old.tool_out_date, :old.due_date );
END IF;
哦,看。该表有四列,但您要插入5.您需要决定是否需要四个或五个并正确声明表。
看起来您还没有employee_id
。 。 。也许你打算:
IF INSERTING THEN
INSERT INTO loan_audit (tool_no, tool_out_date, due_date)
VALUES ( :new.tool_no, :new.tool_out_date, :new.due_date, 'INSERTED', SYSDATE);
ELSIF UPDATING THEN
INSERT INTO loan_audit (tool_no, tool_out_date, due_date)
VALUES ( :old.tool_no, :old.tool_out_date, :old.due_date, 'UPDATED', SYSDATE);
ELSIF DELETING THEN
INSERT INTO loan_audit (tool_no, tool_out_date, due_date)
VALUES ( :old.tool_no, :old.tool_out_date, :old.due_date, 'DELETED', SYSDATE);
END IF;