触发在oracle2中乘以两列

时间:2017-12-27 19:50:54

标签: sql oracle triggers

create or replace trigger BAND_T BEFORE insert or update OF average_song_time, number_of_songs on BAND
for each row
declare
   average_song_time number;
    number_of_songs number;
begin
    if (:new.average_song_time * :new.number_of_songs > 100)  ;
        then 
        raise_application_error(error -2010'Play Time is too high');
    end if;
end;

/ 

想要在Oracle2中将两列相乘,当两列的值达到一定数量时,我的触发器将被触发,只是想知道这个代码在哪里出错?

1 个答案:

答案 0 :(得分:0)

你做了几个错误(不适合的分号,RAISE语句中的ERROR,这里没用的DECLARE部分)。

看看这样一个改进的代码是否能满足您的需求。

create or replace trigger band_t
  before insert or update of average_song_time, number_of_songs
  on band
  for each row
begin
  if :new.average_song_time * :new.number_of_songs > 100 then
     raise_application_error(-20001, 'Play time is too high');
  end if;
end;
/