两张表table1, table2结构一样,结构如下
xm, sex, age
当我改变table1的age时,把table1更改之前的数据插入到table2,做个备份。

解决方案 »

  1.   

    create table table_info(
        xm varchar2(20),
    sex varchar2(20),
    age varchar2(20));
    create table table_info_temp(
        xm varchar2(20),
    sex varchar2(20),
    age varchar2(20));declare 
        cur_update sys_refcursor;
    temp_date table_info_temp%rowtype;
    begin
        open cur_update for select * from table_info where sex='1';
    loop 
    exit when cur_update%notfound;
    fetch cur_update into temp_date;
    insert into table_info_temp values temp_date;
    end loop;
    close cur_update;
    end;
      

  2.   

    create or replace trigger trgname 
    after insert or update or delete on table_info
    for each row 
    declare
        cur_update sys_refcursor;
    temp_date table_info_temp%rowtype;
    begin
        open cur_update for select * from table_info where sex='1';
    loop 
    exit when cur_update%notfound;
    fetch cur_update into temp_date;
    insert into table_info_temp values temp_date;
    end loop;
    close cur_update;
    end;
      

  3.   

    hnzpabc(窗外的猪是多么不一样錯!錯!錯!
    你連new, old都沒引用到
      

  4.   

    CREATE OR REPLACE TRIGGER tr_sec_UpdateAnoy
    after UPDATE ON table_info
    FOR EACH ROW
    BEGIN

    if :old.age <> :new.age then
       insert into table_info_temp values(:old.xm, :old.sex, :old.age);
      END IF;
    END;