0
我試圖創建一個觸發器,允許只插入18歲以上的學生的詳細信息。如何僅允許插入18歲及以上的學生?
表結構:
create table student(
uidno numeric(6) primary key,
fname varchar(20),
lname varchar(20),
dob date
);
這裏是我的PL/SQL觸發器:
create or replace trigger checkAge
before insert
on student
for each row
declare
curr_year int;
dob_year int;
begin
select extract(year from current_date) into curr_year from dual;
select extract(year from dob) into dob_year from :new where uidno = :new.uidno;
if curr_year - dob_year < 18 then
raise_application_error(-20098,'Not above 18 years of age');
end if;
end;
/
我不斷收到以下錯誤: 9/1 PL/SQL:SQL語句忽略 9/55 PLS-00049:壞綁定變量'NEW' 9/60 PL/SQL:ORA-00903:無效的表名
在此先感謝您的 幫幫我。如Barbaros所說,
的問題是在這句話強調了*新*:選擇提取物(從DOB年)爲從'dob_year:新'在哪裏uidno =:new.uidno –
@BarbarosÖzhan是的,我想我已經使用了錯誤的語法。我也嘗試使用:'select extract(year from:new.dob)into dob_year from:new' – Dexter
to use「from:new」作爲表名是錯誤的。它不應該是「從學生」? –