oracle常用視圖及SQL

1、 查看當前用戶的缺省表空間

SQL>select username,default_tablespace from user_users;
2、 查看當前用戶的角色
SQL>select * from user_role_privs;
3、 查看當前用戶的系統權限和表級權限
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;
4、 查看用戶下所有的表
SQL>select * from user_tables;
5、 查看用戶下所有的表的列屬性
SQL>select * from USER_TAB_COLUMNS where table_name=:table_Name;
6、 顯示用戶信息(所屬表空間)
select default_tablespace, temporary_tablespace
  from dba_users     
 where username = 'GAME';
7、 顯示當前會話所具有的權限
SQL>select * from session_privs;
8、 顯示指定用戶所具有的系統權限
SQL>select * from dba_sys_privs where grantee='GAME';
 
9、 顯示特權用戶
select * from v$pwfile_users;
10、 顯示用戶信息(所屬表空間)
select default_tablespace,temporary_tablespace
from dba_users where username='GAME';
11、 顯示用戶的PROFILE
select profile from dba_users where username='GAME';
2 表
1、 查看用戶下所有的表
SQL>select * from user_tables;
2、 查看名稱包含log字符的表
SQL>select object_name,object_id from user_objects
where instr(object_name,'LOG')>0;
3、 查看某表的創建時間
SQL>select object_name,created from user_objects where object_name=upper('&table_name');
4、 查看某表的大小
SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments
where segment_name=upper('&table_name');
 
5、 查看放在Oracle的內存區裏的表
SQL>select table_name,cache from user_tables where instr(cache,'Y')>0;
3 索引
1、 查看索引個數和類別
SQL>select index_name,index_type,table_name from user_indexes order by table_name;
2、 查看索引被索引的字段
SQL>select * from user_ind_columns where index_name=upper('&index_name');
3、 查看索引的大小
SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments
where segment_name=upper('&index_name');
4 序列號
1、 查看序列號,last_number是當前值
SQL>select * from user_sequences;
 
5 視圖
1、 查看視圖的名稱
SQL>select view_name from user_views;
2、 查看創建視圖的select語句
SQL>set view_name,text_length from user_views;
SQL>set long 2000; 說明:可以根據視圖的text_length值設定set long 的大小
SQL>select text from user_views where view_name=upper('&view_name');
6 同義詞
1、 查看同義詞的名稱
SQL>select * from user_synonyms;
7 約束條件     
1、 查看某表的約束條件
SQL>select constraint_name, constraint_type,search_condition, r_constraint_name
from user_constraints where table_name = upper('&table_name');
SQL>select c.constraint_name,c.constraint_type,cc.column_name
from user_constraints c,user_cons_columns cc
where c.owner = upper('&table_owner') and c.table_name = upper('&table_name')
and c.owner = cc.owner and c.constraint_name = cc.constraint_name
order by cc.position;
 
8 存儲函數和過程
1、 查看函數和過程的狀態
SQL>select object_name,status from user_objects where object_type='FUNCTION';
SQL>select object_name,status from user_objects where object_type='PROCEDURE';
2、 查看函數和過程的源代碼
SQL>select text from all_source where owner=user and name=upper('&plsql_name');
9 常用的數據字典:
dba_data_files:通常用來查詢關於數據庫文件的信息
dba_db_links:包括數據庫中的所有數據庫鏈路,也就是databaselinks。
dba_extents:數據庫中所有分區的信息
dba_free_space:所有表空間中的自由分區
dba_indexs:關於數據庫中所有索引的描述
dba_ind_columns:在所有表及聚集上壓縮索引的列
dba_objects:數據庫中所有的對象
dba_rollback_segs:回滾段的描述
dba_segments:所有數據庫段分段的存儲空間
dba_synonyms:關於同義詞的信息查詢
dba_tables:數據庫中所有數據表的描述
dba_tabespaces:關於表空間的信息
dba_tab_columns:所有表描述、視圖以及聚集的列
dba_tab_grants/privs:對象所授予的權限
dba_ts_quotas:所有用戶表空間限額
dba_users:關於數據的所有用戶的信息
dba_views:數據庫中所有視圖的文本
 
10 常用的動態性能視圖:
v$datafile:數據庫使用的數據文件信息
v$librarycache:共享池中SQL語句的管理信息
v$lock:通過訪問數據庫會話,設置對象鎖的所有信息
v$log:從控制文件中提取有關重做日誌組的信息
v$logfile有關實例重置日誌組文件名及其位置的信息
v$parameter:初始化參數文件中所有項的值
v$process:當前進程的信息     
v$rollname:回滾段信息
v$rollstat:聯機回滾段統計信息
v$rowcache:內存中數據字典活動/性能信息
v$session:有關會話的信息
v$sesstat:在v$session中報告當前會話的統計信息
v$sqlarea:共享池中使用當前光標的統計信息,光標是一塊內存區域,有Oracle處理SQL語句時打開。
v$statname:在v$sesstat中報告各個統計的含義
v$sysstat:基於當前操作會話進行的系統統計
v$waitstat:出現一個以上會話訪問數據庫的數據時的詳細情況。當有一個以上的會話訪問同一信息時,可出現等待情況。
總結了一下這些,徹底區別了視圖與數據字典,也不那麼容易混淆。嘿嘿!!!
 
11 常用SQL查詢:
1、查看錶空間的名稱及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
 
2、查看錶空間物理文件的名稱及大小
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
 
3、查看回滾段名稱及大小
select segment_name, tablespace_name, r.status,
(initial_extent/1024) InitialExtent,(next_extent/1024) NextExtent,
max_extents, v.curext CurExtent
From dba_rollback_segs r, v$rollstat v
Where r.segment_id = v.usn(+)
order by segment_name;
      
4、查看控制文件
select name from v$controlfile;
5、查看日誌文件
select member from v$logfile;
6、查看錶空間的使用情況
select sum(bytes)/(1024*1024) as free_space,tablespace_name
from dba_free_space
group by tablespace_name;



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章