create procedure pro
as
begin
insert into tab2 select * from tab1 where col_date between ... and ...;
delete from tab1 where col_date between .. and ..;
commit;
exception
when others then
rollback;
end;
/

解决方案 »

  1.   

    create procedure pro
    as
    begin
    insert into tab2 select * from tab1 where col_date between ... and ...;
    delete from tab1 where col_date between .. and ..;
    commit;
    exception
    when others then
    rollback;
    end;
    /
      

  2.   

    不用主键可以用下面的过程试一下:--I_D_P: PROCEDURE NAME
    --TO_DATE:  CHANGE STRING TO DATECREATE PROCEDURE I_D_P
    AS 
    BEGIN
     
    BEGIN
    DELETE FROM TAB2 WHERE  C_DATE BETWEEN TO_DATE('19920101','YYYYMMDD') AND TO_DATE('20030710','YYYYMMDD'); 
    INSERT INTO TAB2 (SELECT * FROM TAB1 WHERE C_DATE BETWEEN TO_DATE('19920101','YYYYMMDD') AND TO_DATE('20030710','YYYYMMDD') );
    DELETE FROM TAB1 WHERE  C_DATE BETWEEN TO_DATE('19920101','YYYYMMDD') AND TO_DATE('20030710','YYYYMMDD'); EXCEPTION  --选文件异常处理
        WHEN NO_DATA_FOUND THEN  --找不到对应的信息
             <处理语句>
             ROLLBACK;
        WHEN OTHERS THEN   --其它错误
             <处理语句>
             ROLLBACK;
    END;
    END I_D_P;
      

  3.   

    可以通过创建dblink来实现两个数据库间的操作
    create database link dblinkname connect to system identified by manager using 'servicename';
    create procedure pro
    as
    begin
    insert into tab2@dblinkname select * from tab1 where col_date between ... and ...;
    delete from tab1 where col_date between .. and ..;
    commit;
    exception
    when others then
    rollback;
    end;
    /不知道行不行?试试吧
      

  4.   

    我现在希望通过游标将某个时间段的纪录取出来,一条一条的插入到tab2中,然后又将tab1中的该记录删除,不知道这样的能否可以写出来,哪位高手帮帮忙?
      

  5.   

    create databaselink dblinkname connect to username identified by password using servicename;
    create procedure proname(t1 in date,t2 in date)
    as
    col1 tb1.col1%type;
    col2 tb1.col2%type;
     .
     .
     .
    cusor c1 is 
      select * from tb1 where col_date between t1 and t2;
    begin
      fech c1 into col1,col2...
      if c1%found then 
       loop
         insert into tb2@servicename values(col1,col2,....);
         fech c1 into col1,col2...
         exit when c1%notfound;
       end loop;
      end if
      delete from tb1 where col_date between t1 and t2;
      commit;
    exception
       when others then
       rollback;
    end;
      

  6.   

    可不可以在游标打开时删除呢?也就是说,在插入一条到tab2后,接着就将tab1中相应的纪录删除。可以吗?
      

  7.   

    不用那么麻烦,beckhambobo(beckham) ( )说的就可以了,不过最好是加上数据库名