Welcome 微信登录

首页 / 数据库 / MySQL / Oracle 按照Rownum删除数据的一种方法

最近在做Sql到Oracle的移植工作,由于Oracle中没有像Sql 里那样的Identity列,所以遇到很多麻烦,最近遇到了一个要根据自增列的值删除数据的存储过程,弄了半天找到了一种方法。   
  1. /*在Oracle中的操作过程*/  
  2.   
  3. --创建表,由于Oracle中没有identity,所以去掉aid列,在后面使用rownum  
  4. create table TempTable (  
  5.        SearchID number(10,0)  
  6.        )  
  7.   
  8. --删除Rownum为5的值  
  9.   
  10. declare cursor tmp_cursor is select rownum aid,searchid from TempTable for update;  
  11. tmp_record tmp_cursor%rowtype;     
  12. begin  
  13. open tmp_cursor;     
  14. loop     
  15. fetch tmp_cursor into tmp_record;     
  16. exit when tmp_cursor%notfound;     
  17.   
  18. if(tmp_record.aid=5)--如果rownum为5  
  19. then  
  20.   begin  
  21.     delete TempTable where current of tmp_cursor;     
  22.     end;  
  23.     end if;  
  24. end loop;     
  25. close tmp_cursor;     
  26. commit;     
  27. end;    
Oracle教程:ORA-02292和ORA-02297Oracle 层次查询-学习笔记相关资讯      Oracle教程 
  • Oracle中纯数字的varchar2类型和  (07/29/2015 07:20:43)
  • Oracle教程:Oracle中查看DBLink密  (07/29/2015 07:16:55)
  • [Oracle] SQL*Loader 详细使用教程  (08/11/2013 21:30:36)
  • Oracle教程:Oracle中kill死锁进程  (07/29/2015 07:18:28)
  • Oracle教程:ORA-25153 临时表空间  (07/29/2015 07:13:37)
  • Oracle教程之管理安全和资源  (04/08/2013 11:39:32)
本文评论 查看全部评论 (0)
表情: 姓名: 字数