日期:2014-05-17 浏览次数:20773 次
if exists( select 1 from t_gpslatest where f_code='12') (update t_gpslatest set f_style='99',f_longtitude='88',f_latitude='77',f_direction='66',f_speed='55',f_time=sysdate where f_code = '11') else (insert into t_gpslatest(f_code,f_style,f_longtitude,f_latitude,f_direction,f_speed,f_time)values('11','22222','333333','44444','55555','66666',sysdate))
int v_id; select 1 into v_id from t_gpslatest where f_code='12'; if v_d=1 then update t_gpslatest set f_style='99',f_longtitude='88',f_latitude='77',f_direction='66',f_speed='55',f_time=sysdate where f_code = '11'; else insert into t_gpslatest(f_code,f_style,f_longtitude,f_latitude,f_direction,f_speed,f_time)values('11','22222','333333','44444','55555','66666',sysdate); end if
------解决方案--------------------
--你的值都写错了,不是12吗,怎么又成了11了 declare rec int := 0; begin select count(1) into rec from t_gpslatest where f_code='12'; if rec>0 then update t_gpslatest set f_style='99',f_longtitude='88',f_latitude='77' ,f_direction='66',f_speed='55',f_time=sysdate where f_code = '12'; else insert into t_gpslatest(f_code,f_style,f_longtitude,f_latitude,f_direction,f_speed,f_time) values('12','22222','333333','44444','55555','66666',sysdate); end if; commit; exception when others then rollback; dbms_output.put_line('error'); end; /
------解决方案--------------------
取值错了?
------解决方案--------------------
正在学习Oracle
------解决方案--------------------
declare i number; begin select count(*) into i from t_gpslatest where f_code='12'; if i>0 then update t_gpslatest set f_style='99',f_longtitude='88',f_latitude='77',f_direction='66',f_speed='55',f_time=sysdate where f_code = '12'; else insert into t_gpslatest(f_code,f_style,f_longtitude,f_latitude,f_direction,f_speed,f_time) values('11','22222','333333','44444','55555','66666',sysdate); end if; end;
------解决方案--------------------
4楼的当f_code='12'的记录不存在时会有异常, 所以依这样的代码, 不会有新记录插入
9楼的答案也对
6楼的思想严谨,顶.......
楼主可以结贴了.