新聞中心
如何釋放Oracle表空間文件,最好提供一下詳細(xì)的操作過程和說明。拜求!
create
創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),南豐企業(yè)網(wǎng)站建設(shè),南豐品牌網(wǎng)站建設(shè),網(wǎng)站定制,南豐網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,南豐網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
or
replace
procedure
ttt
is
begin
delete
from
bbb
where。。。。。。
;
commit;
execute
immediate
'create
table
aaa
as
select
*
from
bbb';
commit;
--刪除表bbb所有數(shù)據(jù)
execute
immediate
'truncate
table
bbb';
commit;
--將臨時(shí)表aaa的數(shù)據(jù)轉(zhuǎn)移到bbb表中
insert
into
bbb
select
*
from
aaa;
commit;
--刪除臨時(shí)表aaa
execute
immediate
'drop
table
aaa';
commit;
end;
順便說一句,你之前為什么要delete表bbb里的數(shù)據(jù)呢?還有,你存儲(chǔ)過程里沒end
---------補(bǔ)充------
||是用來區(qū)分普通字段和變量字段的
他那個(gè)寫法不和我這個(gè)一樣嗎?
他那個(gè)只不過把我單引號里的sql設(shè)置成了一個(gè)變量,叫str
Oracle 刪除表中記錄 如何釋放表及表空間大小
解決方案
執(zhí)行
alter?table?jk_test?move
或
alter?table?jk_test?move?storage(initial?64k)
或
alter?table?jk_test?deallocate?unused
或
alter?table?jk_test?shrink?space.
注意:因?yàn)閍lter table jk_test move 是通過消除行遷移,清除空間碎片,刪除空閑空間,實(shí)現(xiàn)縮小所占的空間,但會(huì)導(dǎo)致此表上的索引無效(因?yàn)镽OWID變了,無法找到),所以執(zhí)行 move 就需要重建索引。
找到表對應(yīng)的索引
select?index_name,table_name,tablespace_name,index_type,status??from?dba_indexes??where?table_owner='SCOTT'
根據(jù)status 的值,重建無效的就行了。sql='alter index '||index_name||' rebuild'; 使用存儲(chǔ)過程執(zhí)行,稍微安慰。
還要注意alter table move過程中會(huì)產(chǎn)生鎖,應(yīng)該避免在業(yè)務(wù)高峰期操作!
另外說明:truncate table jk_test 會(huì)執(zhí)行的更快,而且其所占的空間也會(huì)釋放,應(yīng)該是truncate 語句執(zhí)行后是不會(huì)進(jìn)入oracle回收站(recylebin)的緣故。如果drop 一個(gè)表加上purge 也不會(huì)進(jìn)回收站(在此里面的數(shù)據(jù)可以通過flashback找回)。
不管是delete還是truncate 相應(yīng)數(shù)據(jù)文件的大小并不會(huì)改變,如果想改變數(shù)據(jù)文件所占空間大小可執(zhí)行如下語句:
alter?database?datafile?'filename'?resize?8g
重定義數(shù)據(jù)文件的大?。ú荒苄∮谠摂?shù)據(jù)文件已用空間的大小)。
另補(bǔ)充一些PURGE知識
Purge操作:
1). Purge tablespace tablespace_name : 用于清空表空間的Recycle Bin
2). Purge tablespace tablespace_name user user_name: 清空指定表空間的Recycle Bin中指定用戶的對象
3). Purge recyclebin: 刪除當(dāng)前用戶的Recycle Bin中的對象。
4). Purge dba_recyclebin: 刪除所有用戶的Recycle Bin中的對象,該命令要sysdba權(quán)限
5). Drop table table_name purge:??刪除對象并且不放在Recycle Bin中,即永久的刪除,不能用Flashback恢復(fù)。
6). Purge index recycle_bin_object_name: 當(dāng)想釋放Recycle bin的空間,又想能恢復(fù)表時(shí),可以通過釋放該對象的index所占用的空間來緩解空間壓力。 因?yàn)樗饕强梢灾亟ǖ摹?/p>
二、如果某些表占用了數(shù)據(jù)文件的最后一些塊,則需要先將該表導(dǎo)出或移動(dòng)到其他的表空間中,然后刪除表,再進(jìn)行收縮。不過如果是移動(dòng)到其他的表空間,需要重建其索引。
1、
SQL?alter?table?t_obj?move?tablespace?t_tbs1;???---移動(dòng)表到其它表空間
也可以直接使用exp和imp來進(jìn)行
2、
SQLalter?owner.index_name?rebuild;?????--重建索引
3、刪除原來的表空間
ORACLE如何清理數(shù)據(jù)可以使表空間立即釋放
select
'drop
table
'
||
table_name
||
'
cascade
constraints'
v_name
from
dba_tables
where
tablespace_name
=
'users';
按照表空間名查詢所有包含的表,并根據(jù)表名拼接刪除語句。
執(zhí)行上面查詢語句生成的語句,即可刪除所有表。
如何釋放oracle臨時(shí)表空間
重新創(chuàng)建一個(gè)臨時(shí)表空間,把原來的默認(rèn)臨時(shí)表空間drop掉(包括里面的臨時(shí)數(shù)據(jù)文件)再重新建立
SQL create temporary tablespace temp2
2 tempfile '/home/oracle/oracle/product/10.2.0/oradata/hatest/temp02.pdf' size 512M reuse
3 autoextend on next 640k maxsize unlimited;
Tablespace created.
SQL alter database default temporary tablespace temp2;
Database altered.
SQL drop tablespace temp including contents and datafiles;
Tablespace dropped.
(注意:由于臨時(shí)表空間的數(shù)據(jù)文件比較大,所以這步可能會(huì)花費(fèi)比較長的時(shí)間)
SQL create temporary tablespace temp
2 tempfile '/home/oracle/oracle/product/10.2.0/oradata/hatest/temp01.pdf' size 512M reuse
3 autoextend on next 640K maxsize unlimited;
Tablespace created.
SQL alter database default temporary tablespace temp;
Database altered.
SQL drop tablespace temp2 including contents and datafiles;
Tablespace dropped.
SQL exit
分享題目:oracle表如何釋放 oracle如何釋放表空間
網(wǎng)站地址:http://ef60e0e.cn/article/hjecsd.html