第一步:创建基于这个表的序列(SEQUENCE)
create sequence sequ_1 increment by 1 start with 1 maxvalue 999999999;第二步:创建一个基于该表(order_d)的before insert 数据触发器,在触发器中使用该SEQUENCE
create or replace trigger_order_d_1
before insert on order_d  --触发时机是before insert(插入)
referencing old as old new as new for each row --逐行触发
begin
new.keyid=sequ_.nextval;
END;

解决方案 »

  1.   

    第一步:创建基于这个表的序列(SEQUENCE)
    create sequence sequ_1 increment by 1 start with 1 maxvalue 999999999;第二步:创建一个基于该表(order_d)的before insert 数据触发器,在触发器中使用该SEQUENCE
    create or replace trigger_order_d_1
    before insert on order_d  --触发时机是before insert(插入前)
    referencing old as old new as new for each row --逐行触发
    begin
    BEGIN  
    SELECT sequ_1.nextval INTO :new.KEYID FROM dual; 
    END;
      

  2.   

    这个我明白,
    我上面写的方法换一个表名就可以成功了
    可是偏偏在KFC_FOODLIST上面不能用,
    报错是:ORA-06552: PL/SQL:Compilation unit analysis terminated
            ORA-06553:  PLS-320:此表达式的类型说明不完整或格式不正确
    难道和我建立的表有关系么?
    可是我的这个表也和其他的表一样有一个 NUMBER 的 NO 字段的啊..郁闷
      

  3.   

    INSERT ON "DB_DESIGN"."KFC_ORDER"
                          *
    ERROR 位于第 2 行:
    ORA-06552: PL/SQL:Compilation unit analysis terminated
    ORA-06553: PLS-320: 此表达式的类型说明不完整或格式不正确