表间复制的存储过程
两张相同字段的表之间进行复制。realtime表和history表,第一步realtime向history表中插一条记录,第二步将相同id的记录更新到realtime表中。create or replace procedure realTime2history(FLD_VEHICLE_NUM varchar2,FLD_LATITUDE number,FLD_LONGITUDE number,FLD_SPEED number,FLD_DIRECTION number,FLD_STATUS varchar2,FLD_GPSDATE date)
as begin
---备份realtime表的记录
insert into gps_history select * from gps_realtime where vehicle_num='京MN8562'
---判断realtime表中记录是否存在
if exists (select * from gps_realtime where vehicle_num='京MN8562')
then
---若存在则更新
begin
update gps_realtime set latitude=FLD_LATITUDE,longtitude=FLD_LONGITUDE,speed=FLD_SPEED,direction=FLD_DIRECTION,status='FLD_STATUS',gpstime=FLD_GPSDATE where vehicle_num='京MN8562'
end
else
---若不存在则插入
begin
insert into gps_realtime (vehicle_num,latitude,longitude,speed,direction,status,gpstime) values('FLD_VEHICLE_NUM',FLD_LATITUDE ,FLD_LONGITUDE , FLD_SPEED,FLD_DIRECTION,'FLD_STATUS' ,gpstime)
end
end if
这样写对不对
------解决方案--------------------
用select count(*) into v_count from gps_realtime where vehicle_num='京MN8562' 来判断是否存在数据呗