oracle常用查询

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

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;

你可能感兴趣的:(oracle,sql)