以下代码包含我在sql上的项目。我很难反复找到触发器编译错误。
Warning: Trigger created with compilation errors.
我正在使用oracle SQL。如果此代码段不够,那么您可以在以下链接中找到整个项目: https://github.com/Shauqi/PhotoGalleryDatabase
create table user1
(
user_id number(10) not null,
name varchar(20),
password number(12)
);
create table myaudit
(
new_name varchar2(30),
old_name varchar2(30),
user_name varchar2(30),
entry_date varchar2(30),
operation varchar2(30)
);
set serveroutput on
CREATE OR REPLACE TRIGGER user1audit
BEFORE INSERT OR DELETE OR UPDATE ON user1
FOR EACH ROW
DECLARE
v_user varchar2 (30); v_date varchar2(30);
BEGIN
SELECT user, TO_CHAR(sysdate, 'DD/MON/YYYY HH24:MI:SS') INTO v_user, v_date FROM dual;
IF INSERTING THEN
INSERT INTO myaudit (new_name,old_name, user_name, entry_date, operation) VALUES(:NEW.NAME, Null , v_user, v_date, 'Insert');
ELSIF DELETING THEN
INSERT INTO myaudit (new_name,old_name, user_name, entry_date, operation) VALUES(NULL,:OLD.NAME, v_user, v_date, 'Delete');
ELSIF UPDATING THEN
INSERT INTO myaudit (new_name,old_name, user_name, entry_date, operation) VALUES(:NEW.NAME, :OLD.NAME, v_user, v_date,'Update');
END IF;
END;
/
答案 0 :(得分:1)
试试这个:
CREATE OR REPLACE TRIGGER user1audit
BEFORE INSERT OR DELETE OR UPDATE ON user1
FOR EACH ROW
BEGIN
IF INSERTING THEN
INSERT INTO myaudit (new_name,old_name, user_name, entry_date, operation) VALUES(:NEW.NAME, Null , user, TO_CHAR(sysdate, 'DD/MON/YYYY HH24:MI:SS'), 'Insert');
ELSIF DELETING THEN
INSERT INTO myaudit (new_name,old_name, user_name, entry_date, operation) VALUES(NULL,:OLD.NAME, user, TO_CHAR(sysdate, 'DD/MON/YYYY HH24:MI:SS') , 'Delete');
ELSIF UPDATING THEN
INSERT INTO myaudit (new_name,old_name, user_name, entry_date, operation) VALUES(:NEW.NAME, :OLD.NAME, user, TO_CHAR(sysdate, 'DD/MON/YYYY HH24:MI:SS'),'Update');
END IF;
END;
/