oracle存储过程数据迁移,oracle 存储过程迁移数据

本文介绍了如何在Oracle数据库中创建表并实现存储过程,用于迁移数据时避免重复插入。通过创建一个名为abingis的存储过程,当abin5表中不存在abin4表已有的记录时,自动将数据迁移。同时,展示了如何设置定时器Job定期执行此迁移操作,确保数据一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

废话少说,首先建表:

-- Create table

create table ABIN4

(

ID1         NUMBER,

NAME1       NVARCHAR2(100),

CREATETIME1 DATE

)

tablespace SYSTEM

pctfree 10

pctused 40

initrans 1

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

-- Create table

create table ABIN5

(

ID1         NUMBER,

NAME1       NVARCHAR2(100),

CREATETIME1 DATE

)

tablespace SYSTEM

pctfree 10

pctused 40

initrans 1

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

建立表迁移存储过程(如果表abin5里面已经存在abin4里面迁移过来的记录,那么就不再执行插入操作):

create or replace procedure abing

is

begin

declare

cursor mycur is select t.id1,t.name1,t.createtime1 from abin4 t;

sid abin4.id1%type;

sname abin4.name1%type;

screatetime abin4.createtime1%type;

num number;

begin

open mycur;

loop

fetch mycur into sid,sname,screatetime;

select count(*) into num from abin5 t where t.id1=sid and t.name1=sname and t.createtime1=screatetime;

if(num=0) then

insert into abin5 (id1,name1,createtime1) values (sid,sname,screatetime);

end if;

exit when mycur%NOTFOUND;

commit;

end loop;

close mycur;

end;

end;

建立Oracle定时器Job,让系统定时的去执行操作:

declare

myjob1 number;

begin

sys.dbms_job.submit(myjob1,'abing;',sysdate,'sysdate+1/2880');

commit;

end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值