Oracle系统表实用操作笔记

时间:2023-03-08 18:37:54

1、取得指定用户的所有表名:

SQL1:

SELECT OWNER AS "对象所有者",
         OBJECT_NAME AS "表名",
         OBJECT_ID AS "对象编号"
    FROM dba_objects
   WHERE owner = 'QDHMFMS' AND OBJECT_TYPE = 'TABLE'
ORDER BY OWNER, OBJECT_TYPE;

SQL2:

 SELECT OWNER AS "对象所有者", TABLE_NAME AS "表名"
    FROM DBA_TABLES
   WHERE owner = 'QDHMFMS'
ORDER BY OWNER, TABLE_NAME;

2、取得指定用户的所有视图

SELECT OWNER  AS "对象所有者",VIEW_NAME AS "视图名称" from DBA_VIEWS  where owner = 'RAXNYB'  ORDER BY OWNER,VIEW_NAME;  

3、取指定用户的表空间和数据文件

SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
D.TOT_GROOTTE_MB "表空间大小(M)",
D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
TO_CHAR(,),'990.99') "使用比",
F.TOTAL_BYTES "空闲空间(M)",
F.MAX_BYTES "最大块(M)"
FROM (SELECT TABLESPACE_NAME,
 ), ) TOTAL_BYTES,
 ), ) MAX_BYTES
FROM SYS.DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
 ), ) TOT_GROOTTE_MB
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
 DESC; --查询数据库表空间剩余大小

--指定路径添加表空间,修改表空间大小 --生产数据库表空间扩展
alter tablespace HMFMS_USER add datafile'E:/oracle/ORADATA/HMFMSDB/hmfms_uer_01.dbf' size 5120m;
ALTER DATABASE DATAFILE 'E:/oracle/ORADATA/HMFMSDB/hmfms_uer_01.dbf' AUTOEXTEND ON NEXT 5M MAXSIZE unlimited;--每次增长至无线
---查询表空间和对应的数据文件
 SELECT T.TABLESPACE_NAME,
         D.FILE_NAME,
         D.AUTOEXTENSIBLE,
         D.BYTES,
         D.MAXBYTES,
         D.STATUS
    FROM DBA_TABLESPACES T, DBA_DATA_FILES D
   WHERE T.TABLESPACE_NAME = D.TABLESPACE_NAME
ORDER BY TABLESPACE_NAME, FILE_NAME;