两个数据库里的两个表,字段都是一样的。 
 T1
  A
  B T2
  A
  B
A是主键。视图 V1里,如果是 T1表的数据,A字段就是 'T1XX' ,如果是 T2表的数据,A字段就是  'T2XX'
更新视图:
update V1 set B='12' where A='T1XX' 报“此视图的数据操纵操作非法”。
请教各位老大,怎么更新?
刚才查了下,触发器可以,怎么建这个触发器,还得拆分下 A字段 ? 请教。。

解决方案 »

  1.   

    视图都是虚表,lz可以更新基本表T1或者T2来实现
      

  2.   


    create table t1 (a char(4) primary key, b number(4))
    /
    create table t2 (a char(4) primary key, b number(4))
    /insert into t1 values('t100',10);
    insert into t2 values('t200',20);
    insert into t1 values('t101',20);
    insert into t2 values('t201',30);
    commit;create view t_v as
    select * from (
     select a,b from t1
     union all
     select a,b from t2
    )
    /create or replace trigger update_tv_trg
    instead of update on t_v
    begin
    -- 阻止更改 a 列的 "t1" 或 "t2" 部分
     if substr(:old.a,1,2)<>substr(:new.a,1,2) then
      raise_application_error(-20001,'Deny update.');
     end if; if substr(:old.a,1,2)='t1' then
      update t1 set a=:new.a,b=:new.b where a=:old.a;
     elsif substr(:old.a,1,2)='t2' then
      update t2 set a=:new.a,b=:new.b where a=:old.a;
     end if;
    end;
    /-- 测试
    update t_v set b=30 where a='t100';update t_v set b=b-10 where a like 't2%';
      

  3.   

    通过视图更新,需要使用INSTEAD OF ,替代触发器
      

  4.   

    create or replace trigger 触发器名 
    instead of update on 视图名
    for each row 
    begin
    update V1 set B='12' where A='T1XX';
    end;
    /