Oracle 按照Rownum删除数据的一种方法 |
发布时间: 2012/8/26 15:27:35 |
最近在做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; 本文出自:亿恩科技【www.enkj.com】 |