表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
空间创立及检查[说明]
表空间创建及查看
1、查看表空间的名称及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size from dba_tablespaces t, dba_data_files d where t.tablespace_name = d.tablespace_name group by t.tablespace_name;
2、查看表空间物理文件的名称及大小
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name;
3、查看回滚段名称及大小
select segment_name, tablespace_name,
r.status,(initial_extent/1024)
InitialExtent,(next_extent/1024) NextExtent, max_extents, v.curext CurExtent From dba_rollback_segs r, v$rollstat v Where r.segment_id = v.usn(+) order by segment_name ;
4、查看控制文件
select name from v$controlfile;
5、查看日志文件
select member from v$logfile;
6、查看表空间的使用情况
select sum(bytes)/(1024*1024) as
free_space,tablespace_name from dba_free_space group by tablespace_name;
SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE, (B.BYTES*100)/A.BYTES "%
USED",(C.BYTES*100)/A.BYTES "% FREE" FROM SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C WHERE
A.TABLESPACE_NAME=B.TABLESPACE_NAME AND
A.TABLESPACE_NAME=C.TABLESPACE_NAME;
7、查看数据库库对象
select owner, object_type, status, count(*) count# from all_objects group by owner, object_type, status;
8、查看数据库的版本
Select version FROM Product_component_version Where SUBSTR(PRODUCT,1,6)='Oracle';
9.查看某个表空间内所占空间大于某个值的段(表或索引):
Select segment_name,bytes FROM dba_segments Where bytes>10000000 AND tablespace_name='tablespace_name';
10.查看所有表空间的碎片程度(值在30以下表示碎片很多)
select
tablespace_name,sum(bytes),sum(free),sum(free)*100/sum(bytes) from (select b.file_id file_ID, b.tablespace_name tablespace_name, b.bytes Bytes, (b.bytes-sum(nvl(a.bytes,0))) used, sum(nvl(a.bytes,0)) free, sum(nvl(a.bytes,0))/(b.bytes)*100 Percent from dba_free_space a,dba_data_files b where a.file_id=b.file_id group by
b.tablespace_name,b.file_id,b.bytes order by b.file_id) group by tablespace_name order by sum(free)*100/sum(bytes);
11.查看自上次数据库启动以来所有数据文件的读写次数
select substr(DF.NAME,1,5) Drive, DF.NAME file_name, (fs.phyblkrd+fs.phyblkwrt) from v$filestat fs,v$datafile df where df.file#=fs.file#;
创建临时表空间:
//创建临时表空间
create temporary tablespace mytest tempfile
'E:\Program\oracle\product\10.1.0\oradata\orcl\mytest.dbf' size 32m autoextend on next 32m maxsize 1024m extent management local;
//创建数据表空间
create tablespace mytest_data logging datafile
'E:\Program\oracle\product\10.1.0\oradata\orcl\mytest_data.dbf' size 32m autoextend on next 32m maxsize 1024m extent management local;
//创建用户并指定表空间
create user testaccount identified by testpwd default tablespace mytest_data temporary tablespace mytest;
//给用户授予权限
grant connect,resource to testaccount; (db2:指定所有权限)
12,创建一个用户:
CREATE USER username IDENTIFIED BY password OR IDENTIFIED EXETERNALLYOR IDENTIFIED GLOBALLY AS ‘CN=user’[DEFAULT TABLESPACE tablespace][TEMPORARY TABLESPACE
temptablespace][QUOTA [integer K[M] ] [UNLIMITED] ] ON tablespace[,QUOTA [integer K[M] ] [UNLIMITED] ] ON tablespace[PROFILES profile_name][PASSWORD EXPIRE][ACCOUNT LOCK or ACCOUNT UNLOCK];
//查看数据库中的所有用户:
select * from all_users;
//or
select * from dba_users
13查询当前用户下的所有表
select 'alter table '|| table_name ||' move tablespace tablespacename;' from user_all_tables;
14.修改表的空间
alter table TABLE_NAME move tablespace TABLESPACENAME
15.查询当前用户下的所有索引
select 'alter index '|| index_name ||' rebuild tablespace tablespacename;' from user_indexes;
16.修改表的索引的空间
alter index INDEX_NAME rebuild tablespace TABLESPACENAME
17.如果要移植LOB字典需要参考以下语法: ALTER TABLE table_name LOB (lob_item) STORE AS [lob_segment]
(
TABLESPACE tablespace_name
(STORAGE.....)
ENABLE|DISABLE STORAGE IN ROW
CHUNK integer
PCTVERSION integer
RETENTION
FREEPOOLS integer
CACHE|NOCACHE|CACHE READS
INDEX lobindexname
(TABLESPACE tablesapce_name
((STORAGE.....))
)
18.查看当前用户的索引和索引所在的表空间 select index_name,tablespace_name from user_indexes
查询当前用户下的表和表所在的表空间 select table_name,tablespace_name from user_indexes
19.修改表中字段SQL语句
update crm_customer t
set t.crm_cussaldptcod='201100',t.crm_cussaldptnam='总经理
部' -- from crm_customer t
where t.CRM_CusSalManNam='聂启春'
20.Oracle11g中用PLSQL导出dmp文件的时候,会提示表不存在的
相关解决办法
select 'alter table '|| a.table_name ||' allocate extent;' from user_tables a where a.table_name not in (select segment_name from user_segments where segment_type = 'TABLE');
20、查看用户和默认表空间的关系。
select username,default_tablespace from dba_users;
21、有时候需要导出某用户下的所有table、view、sequence、trigger
等信息,下面的SQL可以将这些信息select出来:
select * from user_tables;
select * from user_views;
select * from user_sequences;
select * from user_triggers;