如上图所示,我想把一条数据,写成两条。在本表也可以,新建一个表也可以。
我用触发器写了一下,怎么都实现不来,求解。

解决方案 »

  1.   


    create table test(a int , b int , d varchar(10) , e varchar(10));
    insert into test(a,b,d,e) values(1,2,'中国','FJ');select a , NULL b , a c,d,e from test 
    union all
    select NULL a , b , b c,d,e from test ;drop table test purge ; 
      

  2.   


    SQL> create table test(a int , b int , d varchar(10) , e varchar(10));
     
    Table created
    SQL> create table test_bak(a int , b int , c int,d varchar(10) , e varchar(10));
     
    Table created
    SQL> create trigger before_test
      2  before insert on test
      3  for each row
      4  begin
      5    insert into test_bak(a,b,c,d,e) values(:new.a,null,:new.a,:new.d,:new.e) ;
      6    insert into test_bak(a,b,c,d,e) values(null,:new.b,:new.b,:new.d,:new.e) ;
      7  end;
      8  /
     
    Trigger created
    SQL> insert into test(a,b,d,e) values(1,2,'中国','FJ');
     
    1 row inserted
    SQL> select * from test_bak;
     
        A     B     C D          E
    ----- ----- ----- ---------- ----------
        1           1 中国       FJ
              2     2 中国       FJ
    SQL> /
     
        A     B     C D          E
    ----- ----- ----- ---------- ----------
        1           1 中国       FJ
              2     2 中国       FJ
    SQL> drop table test purge;
     
    Table dropped
    SQL> drop table test_bak purge ;
     
    Table dropped
     
    SQL>