一、查询
查询用户所属 表空间
select username,default_tablespace from dba_users where username='xxx'
查询表空间情况
SELECT UPPER(F.TABLESPACE_NAME) "表空间名", D.TOT_GROOTTE_MB "表空间大小(M)", D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)", TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100, 2), '990.99') "使用率", F.TOTAL_BYTES "空闲空间(M)", F.MAX_BYTES "最大块(M)" FROM (SELECT TABLESPACE_NAME, ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES, ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES FROM SYS.DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F, (SELECT DD.TABLESPACE_NAME, ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB FROM SYS.DBA_DATA_FILES DD GROUP BY DD.TABLESPACE_NAME) D WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME ORDER BY 4 DESC;
查询表空间位置及大小
col tablespace_name format a15
col file_id format a5col file_name format a25col total_space format a20SELECT tablespace_name, file_id, file_name, round(bytes / (1024 * 1024), 0) total_space FROM dba_data_files ORDER BY tablespace_name;
二、创建
切换到pdb下
SQL> alter session set container=gnnt_pdb;Session altered.
创建临时表空间
create temporary tablespace user_temp tempfile '+DATA/ORCL/DATAFILE/user_temp.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local;
创建数据库表空间
create tablespace user_data logging datafile '+DATA/ORCL/DATAFILE/user_data.dbf'size 50m autoextend on next 50m maxsize 20480m extent management local;
创建用户并关联创建的表空间
create user test identified by testdefault tablespace user_data temporary tablespace user_temp;
为用户授权
GRANT CREATE ANY VIEW,DROP ANY VIEW,CONNECT,RESOURCE,CREATE SESSION,DBA TO test;
三、修改
修改用户的表空间
换create 为alter
四、删除
以system用户登录,查找需要删除的用户:
--查找用户
select * from dba_users;
--查找工作空间的路径
select * from dba_data_files;
--合并查询
select t.username,t1.tablespace_name,t1.file_name from dba_users tleft join dba_data_files t1on t.default_tablespace=t1.tablespace_name
--删除用户
drop user 用户名称 cascade;
--删除表空间
drop tablespace 表空间名称 including contents and datafiles cascade constraint;