Declare :A int;
Begin
  select count(*) into :A from Table1 where ID='1';
  if :A >0
    begin
      update Table1 set Name='小明' where Id='1';
    end;
  else
    begin
      insert into Table1 (ID,Name) values ('1','小明')
    end;
end;

解决方案 »

  1.   

    DECLARE 
      A NUMBER(18,0);
    BEGIN
      SELECT COUNT(*) INTO A FROM Table1 WHERE ID='1';
      IF A > 0 THEN
        update Table1 set Name='小明' where Id='1';
      ELSE
        insert into Table1 (ID,Name) values ('1','小明');
      END IF;
      COMMIT;
    END;
    /
      

  2.   


    -- 其实这个逻辑,一个 merge into 就能轻松、高效的解决!不需要这么复杂!
      

  3.   


    declare 
      A int;
    begin
     select count(*) into A from Table1 where ID='1';
     IF a>0 THEN
        update Table1 set Name='小明' where Id='1';
     ELSIF
        insert into Table1 (ID,Name) values ('1','小明')
     END IF;
     COMMIT;
    end;