国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

如何有條件的分步刪除數據表中的記錄

2024-07-21 02:05:50
字體:
來源:轉載
供稿:網友
如何有條件的分步刪除數據表中的記錄作者:eygle出處:http://blog.eygle.com日期:february 22, 2005
« 自己動手,豐衣足食 | blog首頁
有時候我們需要分配刪除數據表的一些記錄,分批提交以減少對于undo的使用,本文提供一個簡單的存儲過程用于實現該邏輯。
你可以根據你的需要進行適當調整,本例僅供參考:


sql> create table test as select * from dba_objects;table created.sql> create or replace procedure deletetab 2 /** 3 ** usage: run the script to create the proc deletetab 4 ** in sql*plus, type "exec deletetab('foo','id>=1000000','3000');" 5 ** to delete the records in the table "foo", commit per 3000 records. 6 ** 7 **/ 8 ( 9 p_tablename in varchar2, -- the tablename which you want to delete from 10 p_condition in varchar2, -- delete condition, such as "id>=100000" 11 p_count in varchar2 -- commit after delete how many records 12 ) 13 as 14 pragma autonomous_transaction; 15 n_delete number:=0; 16 begin 17 while 1=1 loop 18 execute immediate 19 'delete from '||p_tablename||' where '||p_condition||' and rownum <= :rn' 20 using p_count; 21 if sql%notfound then 22 exit; 23 else 24 n_delete:=n_delete + sql%rowcount; 25 end if; 26 commit; 27 end loop; 28 commit; 29 dbms_output.put_line('finished!'); 30 dbms_output.put_line('totally '||to_char(n_delete)||' records deleted!'); 31 end; 32 /procedure created.sql> insert into test select * from dba_objects;6374 rows created.sql> /6374 rows created.sql> /6374 rows created.sql> commit;commit complete.sql> exec deletetab('test','object_id >0','3000')finished!totally 19107 records deleted!pl/sql procedure successfully completed.

很簡單,但是想來也有人可以用到。
,歡迎訪問網頁設計愛好者web開發。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武山县| 邓州市| 临泽县| 延津县| 铜梁县| 库尔勒市| 佳木斯市| 石渠县| 河池市| 施秉县| 鸡西市| 毕节市| 大同市| 西畴县| 浮山县| 洮南市| 布尔津县| 沭阳县| 大同县| 武城县| 广饶县| 岑巩县| 黄平县| 锦州市| 青河县| 嘉荫县| 霍林郭勒市| 南陵县| 台前县| 九龙城区| 山丹县| 贡觉县| 常德市| 博湖县| 仪征市| 辽源市| 庆元县| 阳东县| 南平市| 哈巴河县| 凤凰县|