有一个表
  ID ClassName ZoneArea IsLock  
  21 物流天地     3       0
  22 天路         4       0
  23 天路ppp      5       0 将ID为22的 ZoneArea 和 ID为23 ZoneArea一换,实现自定义排序,  下面函数参数为当前ID,该函数从表中找比当前ID的ZoneArea第一大的那条记录,然后交换顺序。 注释中的SQL%ROWCOUNT 第一次为1 第二次为3, 函数可能写得有问题,请大哥帮忙看看 
 create or replace function IndexInfoClassFDown(
  ID NUMBER)
  RETURN NUMBER 
as
currZone tbindexinfoclass.zonearea%Type;   /**//*定义临时变量*/
downZone tbindexinfoclass.zonearea%Type;
downid  tbindexinfoclass.id%Type;
retval number;
begin  
retval:=0;
select zonearea into currZone from tbindexinfoclass where tbindexinfoclass.id=ID and rownum=1;select max(t.id) into downid  from (select * from tbindexinfoclass where tbindexinfoclass.zonearea>currZone and islock=0 order by zonearea asc) t
where rownum=1;/*savepoint point1;*/ 
if downid is not null then
    select zonearea INTO downzone from tbindexinfoclass where tbindexinfoclass.id=downid AND rownum=1;  
    update tbindexinfoclass set zonearea=currZone where tbindexinfoclass.id=downid;
   DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT); /*是1 */
    update tbindexinfoclass set zonearea=downzone where tbindexinfoclass.id=ID;
    DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT); /*是3  不明白为什么*/
    retval:=retval+SQL%ROWCOUNT; 
end if;
COMMIT;
    IF RetVal<2 THEN
       ROLLBACK;
    END IF;
    RETURN retval;
end;
 oracle 不懂,谢谢,哪位大哥指点迷经。。