本帖最后由 arpnet99 于 2012-07-09 15:37:41 编辑

解决方案 »

  1.   

    Oracle 的你去Oracle专区问这样会好些吧
      

  2.   

    oracle好像没有exists写法,mysql有,你select看看有没有记录不就可以了
      

  3.   

    --ORACLE 
    try
    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
      

  4.   


    --你的值都写错了,不是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;
    /
      

  5.   

    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;
      

  6.   

    4楼的当f_code='12'的记录不存在时会有异常, 所以依这样的代码, 不会有新记录插入
    9楼的答案也对
    6楼的思想严谨,顶.......楼主可以结贴了.
      

  7.   

    确实应该是11。后来在oracel板块也开了一个帖子。http://topic.csdn.net/u/20120709/15/f8eba073-2b0d-463b-9a18-bf767f99b507.html?136600295
    好使。谢谢兄弟们。凡是参与的都有分。大家有份是我的一贯作风。