Oracle常用操作
Oracle常用操作
创建表空间
create tablespace 空间名
logging
datafile 'D:\ORACLE-DATA\DATA01.dbf' --(windows目录)
size 50m
autoextend on
next 50m maxsize 10240m --(最大值10G)
extent management local;
查询表空间下所有表名称
select TABLE_NAME,TABLESPACE_NAME from dba_tables where TABLESPACE_NAME='USERS'
Oracle11g导出表时空表不导出的问题处理
1、先查询一下哪些表是空的::
Sql代码:
select table_name from user_tables where NUM_ROWS=0;
2、下面我们通过select 来生成修改语句::
Sql代码:
select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0;
3、执行第2步查询生成的结果脚本,重新导出表即可;
查询数据库中表大小
select SUM(BYTES/1024/1024/1024) as 数据库大小G from dba_segments where owner = '用户名' AND SEGMENT_TYPE = 'TABLE'
查询数据库用户下所有表的名称
select * from dba_segments where owner = '用户名' AND SEGMENT_TYPE = 'TABLE'
当然,我们为了让用户更加便捷,我们增加了图片拖拽功能。
查询表的创建时间
SELECT CREATED FROM USER_OBJECTS WHERE OBJECT_NAME='表名' --表名严格校验大小写
查询表空间利用情况
select
b.file_name 物理文件名,
b.tablespace_name 表空间,
b.bytes/1024/1024 大小M,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M,
substr((b.bytes-sum(nvl(a.bytes,0)))/(b.bytes)*100,1,5) 利用率
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.bytes
order by b.tablespace_name
查询表存储大小(含LOB类型)
LOB类型分为BLOB和CLOB两种:BLOB即二进制大型对象(Binary Large Object),适用于存贮非文本的字节流数据(如程序、图象、影音等);
select a.segment_name,
(select comments from user_tab_comments where table_name=a.segment_name) as t_comments,
round( (sum(a.bytes) + nvl(max(nvl(b.bytes, 0)), 0)) / 1024 / 1024 / 1024 ,2) "Gb"
from user_extents a,
(select d.table_name table_name, sum(nvl(bytes, 0)) bytes
from user_extents c, user_lobs d
where c.segment_name = d.SEGMENT_NAME
group by d.table_name) b
where a.segment_name = b.table_name(+)
and a.segment_name = '表名'
and a.segment_name in( select table_name from user_tables where tablespace_name='表空间名')
group by a.segment_name;
给表空间附加文件
附件表空间文件,或者说是扩充表空间:
ALTER TABLESPACE 空间名
ADD DATAFILE 'D:\ORADATA\USERS02.DBF' --文件所在路径及名称
SIZE 10240M --文件大小10G,一般不超过32G
AUTOEXTEND
ON NEXT 50M
MAXSIZE UNLIMITED;