我有一个EMPLOYEE表,我想创建一个触发器来记录员工佣金变更时(EMPCOMM)。我已经创建了一个EMPLOYEE_COMM_AUDIT表来处理这个问题。我想出了以下代码:
URL fileURL = this.getClass().getResource("config.txt");
File configFile = new File(fileURL);
然而,Oracle SQL告诉我:CREATE OR REPLACE TRIGGER EMPLOYEE_COMM_AUDIT_TRIGGER
BEFORE DELETE OR INSERT OR UPDATE OF EMP_COMM ON EMPLOYEE
IF (NEW.EMP_COMM != OLD.EMPCOMM)
BEGIN
UPDATE EMPLOYEE_COMM_AUDIT
SET EMPLOYEE_COMM_AUDIT.EMP_NUM = EMPLOYEE.EMP_NUM;
SET EMPLOYEE_COMM_AUDIT.CHANGE_DATE = (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') FROM DUAL;
SET EMPLOYEE_COMM_AUDIT.USERNAME = CURRENT_USER;
SET EMPLOYEE_COMM_AUDIT.ACTION = NULL;
SET EMPLOYEE_COMM_AUDIT.OLD_COMM = OLD.EMPCOMM;
SET EMPLOYEE_COMM_ADUDIT.NEW_COMM = NEW.COMM;
DBMS_OUTPUT_LINE("Employee Commisions Audit has been updated);
END;
,但我没有在任何地方获得任何红色下划线来指示故障位置。
有人可以帮帮我吗?我试图在这些论坛上看一下,但我似乎无法在任何地方找到可靠的回复。
提前致谢。
答案 0 :(得分:2)
您的UPDATE
语法错误:
UPDATE EMPLOYEE_COMM_AUDIT
SET CHANGE_DATE = SYSDATE,
USERNAME = CURRENT_USER,
ACTION = NULL,
OLD_COMM = OLD.EMPCOMM,
NEW_COMM = NEW.COMM
WHERE EMP_NUM = :NEW.EMPNUM;
变化和假设:
SET
只出现一次。SET
表达式由commma而非分号分隔。sysdate
转换为日期以将其分配到日期列。WHERE
子句来指定应更新哪一行。这修复了update
(或试图);可能还有其他问题。