zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

Oracle数据库查询登录用户名所属表空间及其使用情况

2023-03-31 11:07:49 时间

Oracle数据库可以查询登录的用户名所属表空间以及表空间的使用情况吗?答案是肯定的,不过执行select username,default_tablespace from dba_users order by username需要有dba的权限才行,本文我们就介绍这一实现方法,接下来就让我们来一起了解一下吧。

1、查看用户使用的缺省表空间名称

首先需要知道你登录的用户名,然后以sysdba登录,然后执行下列的语句:

 

  1. sqlplus / as sysdba  
  2.  
  3. select username,default_tablespace from dba_users; 

 

2、查看表空间总大小,及其已使用大小

 

  1. select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",  
  2.  
  3. round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"  
  4.  
  5. from  
  6.  
  7. (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,  
  8.  
  9. (select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b  
  10.  
  11. where a.tablespace_name=b.tablespace_name  
  12.  
  13. order by ((a.bytes-b.bytes)/a.bytes) desc; 

 

关于Oracle数据库查看登录用户名所属表空间的知识就介绍到这里了,如果您想了解更多Oracle数据库的知识,可以看一下这里的文章:http://database.51cto.com/oracle/,相信一定可以带给您收获的。

【编辑推荐】

  1. Oracle数据库账号频繁被锁定的原因排查
  2. SQL Server 2005数据库镜像相关知识概述
  3. Oracle数据库如何创建虚拟列和复合触发器
  4. MySQL数据库binlog记录的时间戳失序的原因
  5. SQL Server数据库使用DBCC ShowContig检查索引碎片