我正在尝试在oracle apex中创建一个触发器,它将选择我在UniversityRefNo列中的所有数据,并且不允许用户输入已存在的值。但是,我一直收到这个错误:"ORA-24344: success with compilation error."
如果有人能告诉我,我做错了哪个会很棒。
CREATE TABLE VOLUNTEER(
Volunteer_id NUMBER(5) PRIMARY KEY,
Title VARCHAR2(5),
VolName VARCHAR2(30),
UniversityRefNo VARCHAR2(10),
Address_Line_1 VARCHAR2(30),
Address_Line_2 VARCHAR2(12),
PostCode VARCHAR2(12),
Mobile_Number NUMBER(12),
Home_Number NUMBER(12),
Email VARCHAR2(25),
Ethnic_Group VARCHAR2(10),
VolunteerType VARCHAR2(10),
Register_Disable VARCHAR2(3),
Gender VARCHAR2(1),
Medical_Details VARCHAR2(20),
PassPortNumber NUMBER(10),
Nationality VARCHAR2(10),
Passport_Expiry_Date DATE,
Date_of_Birth DATE,
Course_Name VARCHAR2(20),
Course_Year VARCHAR2(10),
Area_of_work VARCHAR2(15),
StaffManagerName VARCHAR2(20),
StaffManagerEmail VARCHAR2(20),
StaffManagerPhone VARCHAR2(12));
CREATE or replace trigger unirefnoTrigger
before insert or update of UniversityRefNo ON VOLUNTEER for each row
begin
SELECT UniversityRefNo from VOLUNTEER
if(UniversityRefno = :new.UniversityRefNo) then raise application error(UniversityRefNO || :new.UniversityRefNo || 'already exists');
end if;
end;
答案 0 :(得分:0)
如果你想让大学的RefNo列独一无二而你不需要制作一个触发器就可以简单地创建一个这样的唯一约束:
ALTER TABLE VOLUNTEER
ADD CONSTRAINT UniversityRefNo_UK UNIQUE (UniversityRefNo);
以下是学习目的,您可以创建触发器来执行相同的操作,但我不建议您使用它。
CREATE or replace trigger unirefnoTrigger
before insert or update of UniversityRefNo ON VOLUNTEER for each row
university_count number;
begin
SELECT count(*) into university_count from VOLUNTEER where UniversityRefno=:new.UniversityRefNo;
if university_count<>0 then
raise application error(-20000, :new.UniversityRefNo || ' already exists');
end if;
end;