<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 手機與無(wú)線(xiàn)通信 > 設計應用 > 教你快速掌握分別刪除數據表記錄的方法

教你快速掌握分別刪除數據表記錄的方法

作者: 時(shí)間:2017-06-13 來(lái)源:網(wǎng)絡(luò ) 收藏
很多情況下我們需要分別刪除的一些記錄,分批來(lái)提交以此來(lái)減少對于Undo的使用,下面我們提供一個(gè)簡(jiǎn)單的存儲過(guò)程來(lái)實(shí)現此邏輯。


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 ** Condition with default value '1=1' and default Commit batch is 10000.

7 **/

8 (

9 p_TableName in varchar2, -- The TableName which you want to delete from

10 p_Condition in varchar2 default '1=1', -- Delete condition, such as id>=100000

11 p_Count in varchar2 default '10000' -- 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.


注釋?zhuān)涸诖藢?shí)例中修正了一下,增加了2個(gè)缺省值,以下是具體過(guò)程:


create or replace procedure deleteTab

(

p_TableName in varchar2,

-- The TableName which you want to delete from

p_Condition in varchar2 default '1=1',

-- Delete condition, such as id>=100000

p_Count in varchar2 default '10000'

-- Commit after delete How many records

)

as

pragma autonomous_transaction;

n_delete number:=0;

begin

while 1=1 loop

EXECUTE IMMEDIATE

'delete from '||p_TableName||'

where '||p_Condition||' and rownum = :rn'

USING p_Count;

if SQL%NOTFOUND then

exit;

else

n_delete:=n_delete + SQL%ROWCOUNT;

end if;

commit;

end loop;

commit;

DBMS_OUTPUT.PUT_LINE('Finished!');

DBMS_OUTPUT.PUT_LINE('Totally '||to_char(n_delete)||' records deleted!');


關(guān)鍵詞: 數據表

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>