create table single (
  id         char(20),
  start_time char(10),
  end_time   char(10),
  sum        char(10),
  username   varchar2(10),
  subject    varchar2(10)
);create index idx_single_un on signle (username)
  tablespace indx;create index idx_single_subject on single (subject)
  tablespace indx;create or replace procedure test_single(
  sid in string,
  starttime in string,
  endtime in string,
  sum1 in string,
  user in string,
  sub in string)  as
begin
  update single 
     set start_time = starttime ,
         end_time = endtime, 
         sum = sum1 
   where userName = user 
     and subject = sub;   IF SQL%NOTFOUND THEN
     INSERT INTO single (id,start_time,end_time,userName,subject,sum)
                 VALUES (sid,starttime,endtime,user,sub,sum1);   END IF;   commit;
end;
/

解决方案 »

  1.   

    我看你的PL/Sql已经够优化了,没啥可改的
      

  2.   

    userName和subject字段建立复合索引
      

  3.   

    create or replace procedure test_single(sid in string,starttime in string,endtime in string,
           sum1 in string,user1 in string,sub in string)  is
    begin
      merge into single b
      using (select user1 sub from dual) 
      on (b.userName=user1 and b.subject=sub)
      when matched then
         update set start_time =starttime ,end_time=endtime, sum=sum1 
      when not matched then
            INSERT  values (sid,starttime,endtime,sum1,user1,sub);
    end test_single;
      

  4.   

    升级到9i,但是用上面的merge还是有问题,谁能帮我调试一下