Oracle 常用資料字典表、檢視的總結

dbasdk發表於2017-12-04
Oracle 常用資料字典表、檢視的總結
一資料字典的分類
1.靜態資料字典表的 2.靜態資料字典檢視 3 動態資料字典表 4 動態資料字典檢視
二 資料字典的使用
1.靜態資料字典表的使用
靜態資料字典表只能由ORACLE 進行維護。
2.靜態資料字典檢視的使用 *
通常使用者透過對靜態資料字典檢視的查詢可以獲取所需 i要的所有資料庫資訊。
Oracle 靜態資料字典分類
名稱字首                                       含義  
user_                          包含了當前資料庫使用者所擁有的所有的模式物件的資訊
all_                            包含了當前資料庫使用者可以訪問的所有的模式物件的資訊
dba_                           包含了所有資料庫物件資訊,只有具有DBA角色的使用者才嫩而過訪問的這些檢視 
例如:
select * from dba_tables
select  * from all_tables
select   * from user_tables;

注: dba_ 開頭的 必須是sys 使用者所有 ,非 sys 使用者 需要在前面加 sys 字首
下面都是一些常用的檢視家族,都有一個DBA_ ALL_ USER_ 的檢視 
col_privs   包含了表的列許可權資訊,包含授予者,被授予者和許可權名稱等資訊,
extents     儲存分配資訊,包括資料段名 表空間名和分割槽編號,分割槽大小
indexes    索引資訊  包含索引型別, 唯一性, 索引作用等表的資訊
ind_columns   索引列資訊  包括索引上的列的排序方式等資訊
object      物件資訊, 包括物件名稱 型別  建立時間 等資訊
segments  表和索引的資料段資訊,包括表空間,儲存設定等資訊
sequences   序列資訊 包含序列名稱 ,迴圈性,最大值等資訊
source    除觸發器之外的所有儲存過程,函式,包的原始碼資訊 
synonyms 同義詞資訊   包括引用的物件等資訊
sys_privs   系統許可權資訊 包括系統許可權名稱 授予者
tab_columns   表和檢視的列資訊 ,包括列的資料型別等資訊 
tab_privs  表許可權資訊 
tables  表資訊 包括表所屬的表空間 ,儲存引數 ,資料行數量等資訊。
triggers   觸發器資訊 包括觸發器的型別,事件。觸發器體等資訊
users 使用者資訊 。包括使用者臨時和預設的表空間的型別
views   檢視 資訊  

看一下許可權檢視 
role_sys_privs  角色擁有的系統許可權檢視
role_tab_privs  角色擁有的物件許可權
user_role _ privs  使用者擁有的角色 
user_sys_privs   使用者擁有的許可權的角色
user_tab_privs_mads    使用者分配的關於表物件許可權
user_tab_privs_recd  使用者擁有的關於表物件許可權
user_col_privs_mads  使用者分配的關於列的物件許可權
user_col_privs_recd  使用者擁有的關於列的物件許可權 

3.  動態效能表是資料庫例項啟動後  建立的表。動態效能表都資料SYS 使用者; 用於存放資料庫在執行的過程中的效能相關的資訊。 透過以下的檢視檢視 
 select name from  v_$fixed_table;

4.動態效能檢視的使用;
只有sys 使用者和擁有DBA 角色的使用者可以訪問 。
在資料庫啟動到 NOMOUNT 的狀態時 可以訪問 v$ parameter v$sga  v$session v$process v$instance v$version v$option 
當資料庫啟動到 mount 的狀態時 我們還可以訪問 v$ log v$logfiel v$datafile v$controlfile  v$ database v$thread  v$datafile_header  
當資料庫完全啟動後。可以訪問 v_$fixed_table
v$access   包含當前被鎖定的資料庫物件及正在訪問他們的會話
v$archive  包含歸檔所需的重做日誌檔案中的資訊
v$ archived_log   包含從控制檔案中獲取的歸檔日誌資訊。
v$archive_processes  包含於一個例項相關的arch 程式的狀態資訊 
v$ backup   包含聯機資料檔案的備份狀態資訊 
v$backup_async_io   包括從控制檔案中獲取的備份集的資訊 
v$ backup_corruption   包含從控制檔案中獲取的有關資料檔案備份中損壞的資訊。
v$ backup_datafile   包含從控制檔案中獲取的備份的資料檔案和備份控制檔案的資訊
v$ backup_device   包含支援備份裝置的資訊
v$backup_piece     包含從控制檔案中獲取的備份塊的資訊
v$backup_redolog    包含從控制檔案中獲取的關於備份集的歸檔日誌的資訊
v$backup_set    包含從控制檔案中獲取的備份集的資訊
v$bgprocess 包含資料庫後臺程式資訊
v$ buffer_pool   包含當前例項中所有可用緩衝池的資訊
v$ buffer_pool_statistics  包含當前例項所有可用緩衝池的統計資訊
v$ cache   包含當前例項的SGA 中的每一塊的頭部資訊
v$context   包含當前對話的屬性資訊。
v$controlfile   包含控制檔案資訊
v$ controlfile_record_section   包含控制檔案記錄部分的資訊
v$ copy_curruption 包含從控制問價中獲取的資料檔案副本損壞的資訊 
v$database  包含從控制檔案中獲取的資料庫資訊 
v$datafile   包含從控制檔案中獲取的資料檔案資訊
v$datafile_copy  包括從控制檔案中獲取的資料檔案副本的資訊
v$datafile_header  包含資料檔案頭部資訊
v$ db_object_cache  包含快取在庫高速緩衝中的資料庫物件資訊
v$db_pipes   包含當前資料庫中的管道資訊
v$deleted_object   包含從控制檔案中獲取的被刪除的歸檔日誌,資料檔案副本和備份塊的資訊
v$ dispatcher_rate   包含排程程式速率統計量的資訊
v$ dispatche   包含排程程式的資訊
 v$ DLM_ALL_LOCKS  包含當前所有鎖
v$ DLM_CONVERT_LOCAL   包含本地鎖轉換操作所消耗的時間的資訊 
v$ EVENT_NAME   包含等待時間的資訊
v$ fixed_table   包含所有可用的動態效能檢視和動態效能表的資訊 
v$ sysstat   包含當前例項的效能統計資訊
v$ instance  包含當前例項的詳細資訊 
v$sga  包含 SGA 區的主要組成部分的資訊 
v$ sgainfo   包含SGA 區的詳細訊息 
v$ parameter 包含初始化引數資訊 
v$ sversion   包含Oracle 版本資訊 
v$ option  包含已安裝的 Oraclette元件的選項資訊 
v$session   包含當前所有會話資訊 
v$process   包含當前系統所有程式資訊 
v$ bgprocess  包含資料庫所有後臺程式資訊 
v$ database  包含當前資料庫資訊
v$ controlfile  包含當前資料庫所有控制檔案資訊
v$ datafile   包含當前資料庫所有的資料檔案的資訊 
v$ dbfile   包含所有資料檔案的編號資訊 
v$ logfile   包含當前資料庫所有的重做日誌檔案資訊
v$ log  包含當前資料庫重做日誌檔案資訊 
v$ log_history  包含重做日誌檔案切換情況的歷史資訊
v$ thread  包含當前資料庫執行緒的資訊
v$ lock 包含鎖的資訊 
v$ locked_object   包含被加鎖的資料庫物件資訊 
v$ rollname 包含當前處於聯機狀態的回退資訊 
v$ rollstat    包含當前所有的回退段的統計資訊 
v$ tablespace  包含當前資料庫所有表空間資訊
v$ tempfile   包含當前資料庫多有的臨時資料檔案的資訊 ;


檢視當前使用者的預設表空間
SQL>select username,default_tablespace from user_users;
檢視當前使用者的角色
SQL>select * from user_role_privs;

檢視當前使用者的系統許可權和表級許可權
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;

檢視使用者下所有的表
SQL>select * from user_tables;

檢視使用者下所有的表的列屬性
SQL>select * from USER_TAB_COLUMNS where table_name=:table_Name;

顯示使用者資訊(所屬表空間)
select default_tablespace,temporary_tablespace 
from dba_users where username='GAME';

1、使用者

檢視當前使用者的預設表空間
SQL>select username,default_tablespace from user_users;

檢視當前使用者的角色
SQL>select * from user_role_privs;

檢視當前使用者的系統許可權和表級許可權
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;

顯示當前會話所具有的許可權
SQL>select * from session_privs;

顯示指定使用者所具有的系統許可權
SQL>select * from dba_sys_privs where grantee='GAME';

顯示特權使用者
select * from v$pwfile_users;

顯示使用者資訊(所屬表空間)
select default_tablespace,temporary_tablespace 
from dba_users where username='GAME';

顯示使用者的PROFILE
select profile from dba_users where username='GAME';

2、表

檢視使用者下所有的表
SQL>select * from user_tables;

檢視名稱包含log字元的表
SQL>select object_name,object_id from user_objects
where instr(object_name,'LOG')>0;

檢視某表的建立時間
SQL>select object_name,created from user_objects where object_name=upper('&table_name');

檢視某表的大小
SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments
where segment_name=upper('&table_name');

檢視放在Oracle的記憶體區裡的表
SQL>select table_name,cache from user_tables where instr(cache,'Y')>0;

3、索引

檢視索引個數和類別
SQL>select index_name,index_type,table_name from user_indexes order by table_name;

檢視索引被索引的欄位
SQL>select * from user_ind_columns where index_name=upper('&index_name');

檢視索引的大小
SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments
where segment_name=upper('&index_name');

4、序列號

檢視序列號,last_number是當前值
SQL>select * from user_sequences;

5、檢視

檢視檢視的名稱
SQL>select view_name from user_views;

檢視建立檢視的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、同義詞

檢視同義詞的名稱
SQL>select * from user_synonyms;

7、約束條件

檢視某表的約束條件
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、儲存函式和過程

檢視函式和過程的狀態
SQL>select object_name,status from user_objects where object_type='FUNCTION';
SQL>select object_name,status from user_objects where object_type='PROCEDURE';

檢視函式和過程的原始碼
SQL>select text from all_source where owner=user and name=upper('&plsql_name');

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29734436/viewspace-2148243/,如需轉載,請註明出處,否則將追究法律責任。

相關文章