create or replace trigger trig_seq_plan
before insert or delete
on t_plan for each row
declare
begin
if inserting then
select seq_plan.nextval into:new.plan_id from dual;
end if;
update t_task set status='实施中', plan_number=(select count(*) from t_plan where task_id=:new.task_id)+1 where task_id=:new.task_id;
end;

解决方案 »

  1.   

    create or replace trigger trig_seq_plan
    before insert or delete
    on t_plan for each row
    declare
    begin
    if inserting then
    select seq_plan.nextval into :new.plan_id from dual;--空格
    end if;
    update t_task set status='实施中', plan_number=(select count(*) from t_plan where task_id=:new.task_id)+1 where task_id=:new.task_id;
    end;
      

  2.   

    暂时修改一下明显的语法错误:CREATE OR REPLACE TRIGGER trig_seq_plan
    BEFORE INSERT OR DELETE
    ON t_plan FOR EACH ROW
    DECLARE
    BEGIN
        IF INSERTING THEN
            SELECT seq_plan.nextval INTO :new.plan_id FROM dual;
        END IF;
        UPDATE t_task SET status='实施中', 
            plan_number=(SELECT COUNT(*) FROM t_plan 
                         WHERE task_id = :NEW.task_id) + 1 
        WHERE task_id = :NEW.task_id;
    END;
    如果可以把创建序列seq_plan和创建t_plan和t_task表的语句也贴一下,可以做进一步的测试。