---
title: "oracle常用查询"
author: "duyunfengsolo"
date: "2011-05-20T14:56:08Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2011-06-14T15:23:46Z"
id: 1051747
url: "https://solodu.iteye.com/blog/1051747"
---

查询库表中大数据量的表：

select owner, segment\_name, sum(bytes) / 1024 / 1024  M  
  from dba\_segments  
 where segment\_type in ('TABLE', 'INDEX') and owner='BOMC2'  
 group by segment\_name, owner  
 order by M desc;

 

//创建表空间  
create tablespace test\_tablespace datafile '/opt/oracle/product/9.2.0/dbs/test\_tablespace.dbf' size 512M  AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED default storage (initial 128K next 2M pctincrease 0);

//创建公司的：

(1)先在库中查看下创建的文件都放在什么地方？select * from dba\_data\_files;

(2)create tablespace echanel\_es datafile '/data/oracle/oradata/MOMC/test.dbf'  
size 2048M  AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED  
default storage (initial 128K next 2M pctincrease 0);

 

--initial 128K，因为，用户建在表空间上，而表建在用户里，为用户所拥有，  
\--用户继承数据表空间的存储参数，表继承用户的存储参数  
\--如果initial设的过大，如：5M，则每建一个空表就要占用5M的空间，即使一条记录也没有  
\--AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED，设置数据文件自动扩展，每一次扩展增加5M，最大空间不受限

参考命令：删除表空间  
drop tablespace test\_tablespace including contents;

更改表空间的所有者：  
ALTER TABLESPACE test\_tablespace OWNER TO aaaa;

//更改表空间大小  
alter database datafile '/oradata/k12db/test\_tablespace.dbf' resize 1000M;

alter database datafile '/data/oracle/oradata/MOMC/test.dbf' resize 2000M;

 

//查看字符集  
select parameter,value from V$NLS\_PARAMETERS

//查看表空间信息  
SELECT FILE\_NAME,TABLESPACE\_NAME,BYTES,USER\_BLOCKS FROM DBA\_DATA\_FILES;

 

create user bomc identified by bomc default tablespace test\_tablespace temporary tablespace TEMP

GRANT CREATE USER,DROP USER,ALTER USER,CREATE ANY VIEW,DROP ANY VIEW,EXP\_FULL\_DATABASE,IMP\_FULL\_DATABASE,DBA,CONNECT,RESOURCE,CREATE SESSION TO bomc;

 

 

   (1)数据库名字:echannel 。  
   (2)以sys/oracle(用户名和密码,我本地sys的密码是oracle)身份以dba的方式登录刚创建的echannel数据库后，然后在其里面写sql用来创建用户名和密码.        
     (3)drop user duyf cascade;  
       删除表空间：前提表空间没有被其他用户所使用。  
       including contents：删除表空间中的内容，如果表中有内容而未加此参数，则表删除不掉。  
       cascade onstraints：删除表中的外键参照。  
       drop tablespace duyf including contents and datafiles cascade onstraints;

 

(1)创建E的表空间：  
create temporary tablespace ZFDB    
tempfile 'D:\\oracle\\product\\10.2.0\\oradata\\user\_temp.dbf'   
size 50m    
autoextend on    
next 50m maxsize 20480m    
extent management local; 

create tablespace ZFDB    
logging    
datafile 'D:\\oracle\\product\\10.2.0\\oradata\\user\_data.dbf'   
size 50m    
autoextend on    
next 50m maxsize 20480m    
extent management local;

(2)删除表空间  
DROP TABLESPACE ZFDB INCLUDING CONTENTS AND DATAFILES;

(3)  
\-- Create the user  
  create user ZF  
  identified by "ZF"  
  default tablespace ZFDB  
  profile DEFAULT;

  -- Grant/Revoke role privileges(都是针对用户名)  
  grant connect to ZF;  
  grant dba to ZF;  
  grant exp\_full\_database to ZF;  
  grant imp\_full\_database to ZF;  
  grant resource to ZF;

  -- Grant/Revoke system privileges  
  grant alter user to ZF;  
  grant create any view to ZF;  
 grant create session to ZF;  
 grant create user to ZF;  
 grant drop any view to ZF;  
 grant drop user to ZF;  
 grant unlimited tablespace to ZF;