日期:2014-05-17  浏览次数:20635 次

oracle存储过程
创建一个存储过程,要求判断数据库中的XM_XXK表中是否存在记录,如果存在记录立即清空表中的记录,然后从另外一个数据库把数据迁移到该表上。

------解决方案--------------------
写个大概:
SQL code
create or replace procedure copy_data
is
  vn_cnt number(4) := 0;
begin
 select count(*) into vn_cnt from XM_XXK;
 if vn_cnt <> 0 then
   delete from XM_XXK;
 end if;
   insert into XM_XXK as select * from XM_XXX@db_link; --db_link是另外一个数据库的DBLINK;
   commit;
end;

------解决方案--------------------
改一下一楼的.

create or replace procedure copy_data
is
vn_cnt number(4) := 0;
begin
 select count(*) into vn_cnt from XM_XXK;
 if vn_cnt <> 0 then
truncate table XM_XXK; --此次避免多次执行后生成高水位线,降低查询速度.
 end if;
insert into XM_XXK as select * from XM_XXX@db_link; --db_link是另外一个数据库的DBLINK;
commit;
end;