create or replace trigger gw_deptno
after insert
on scott.dept
for each row
begin
if deptno>20 then
:new.deptno:=25;
else
:new.deptno:=15;
end if;
end;

解决方案 »

  1.   

    就是插入一条数据 如果deptno>20 的话把deptno=25  deptno<20 的话 把deptno=15呀
      

  2.   


    create or replace trigger gw_deptno
    before insert on scott.dept --用before触发器,可以修改:new值
    for each row
    begin
        if :new.deptno>20 then
           :new.deptno := 25;
        else
           :new.deptno:=15;
        end if;
    end;
      

  3.   

    /*
    就结贴了!这样写是可以的,个人觉得没多大的意思,
    因为deptno是主键,你下次要插入数据的话就会报主键重复的错误的
    */
    已写入 file afiedt.buf  1  create or replace trigger gw_deptno
      2  before insert on dept
      3  for each row
      4  begin
      5  if :new.deptno>20 then
      6  :new.deptno:=25;
      7  else
      8  :new.deptno:=15;
      9  end if;
     10* end;
    SQL> /触发器已创建SQL> insert into dept(deptno) values(90);已创建 1 行。SQL> commit;提交完成。SQL> select * from dept;    DEPTNO DNAME          LOC
    ---------- -------------- -------------
            60 dfsdf          we
            70 jiujiang
            50 NANCHANG
            10 ACCOUNTING     NEW YORK
            25
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON已选择8行。SQL> insert into dept(deptno) values(10);已创建 1 行。SQL> commit;提交完成。SQL> select * from dept;    DEPTNO DNAME          LOC
    ---------- -------------- -------------
            60 dfsdf          we
            70 jiujiang
            50 NANCHANG
            10 ACCOUNTING     NEW YORK
            15
            25
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON已选择9行。