create or replace trigger text_update_szzrk
after insert or update or delete on text_szrk1
for each row
declare
begin
-- local variables here
if inserting then
    if :NEW.性别='2' and is_date(:NEW.出生日期)=1 then
    if to_char(sysdate,'yyyy') -to_char(to_date(:NEW.出生日期,'yyyymmdd'),'yyyy') between 15 and 49 then
     insert into text_szrk1(主键,姓名,性别,出生日期,更新时间)values(:NEW.主键,:NEW.姓名,:NEW.性别,:NEW.出生日期,'2012-03-10');
elsif deleting then
    delete from jsrk_sj where 主键=:old.主键;
else
     update jsrk_sj set 操作类型=2,姓名=NEW.姓名 where 主键=:old.主键;
end if;
end 触发器报TRIGGER DW.TEXT_UPDATE_SZZRK 编译错误错误:PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
       
          if
行:19
请各位高手,帮忙查看一下如何编写

解决方案 »

  1.   

    你这if 嵌套看起来怎么这么纠结呢!!
    你要的逻辑是干什么,红色的部分是你少的两个end if
    create or replace trigger text_update_szzrk
    after insert or update or delete on text_szrk1
    for each row
    declare
    begin
    if inserting then
      if :NEW.性别='2' and is_date(:NEW.出生日期)=1 then
      if to_char(sysdate,'yyyy') -to_char(to_date(:NEW.出生日期,'yyyymmdd'),'yyyy') between 15 and 49 then
      insert into text_szrk1(主键,姓名,性别,出生日期,更新时间)values(:NEW.主键,:NEW.姓名,:NEW.性别,:NEW.出生日期,'2012-03-10');
     end if;
    end if;

    elsif deleting then
      delete from jsrk_sj where 主键=:old.主键;
    else
      update jsrk_sj set 操作类型=2,姓名=NEW.姓名 where 主键=:old.主键;
    end if;
    end
      

  2.   

    上面的还是不对,你这是after insert,update 触发器
    怎么会有elsif deleting then 语句? 这语句写了等于没写
    能把你的处理逻辑说下么!
      

  3.   

    不用管他逻辑是什么了,反正if的语法肯定是有问题的了if 条件1 then
       --嵌套if
       if 条件2 then
       end if;elseif 条件3 then
    ...
    end if;