你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle 按照Rownum删除数据的一种方法

[日期:2011-08-04] 来源:Linux社区  作者:appleflashstudio [字体:大 中 小]
最近在做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;    
linux
相关资讯       Oracle教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款