Oracle數(shù)據(jù)字典的學(xué)習(xí)總結(jié) |
發(fā)布時間: 2012/8/9 17:44:19 |
下面按類別列出一些Oracle用戶常用數(shù)據(jù)字典的查詢使用方法。 一、用戶 查看當(dāng)前用戶的缺省表空間SQL>SELECT username,default_tablespace FROM user_users; 查看當(dāng)前用戶的角色SQL>SELECT * FROM user_role_privs; 查看當(dāng)前用戶的系統(tǒng)權(quán)限和表級權(quán)限SQL>SELECT * FROM user_sys_privs;SQL>SELECT * FROM user_tab_privs; 二、表 查看用戶下所有的表SQL>SELECT* FROM user_tables; 查看名稱包含log字符的表SQL>SELECT object_name,object_id FROM user_objects WHERE INSTR(object_name,'LOG')>0; 查看某表的創(chuàng)建時間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的內(nèi)存區(qū)里的表SQL>SELECT table_name,cache FROM user_tables WHERE INSTR(cache,'Y')>0; 三、索引 查看索引個數(shù)和類別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'); 四、序列號 查看序列號,last_number是當(dāng)前值SQL>SELECT * FROM user_sequences; 五、視圖 查看視圖的名稱SQL>SELECT view_name FROM user_views; 查看創(chuàng)建視圖的select語句SQL>SELECT view_name,text_length FROM user_views;SQL>SET long 2000; //說明:可以根據(jù)視圖的text_length值設(shè)定set long 的大小SQL>SELECT text FROM user_views WHERE view_name=UPPER('&view_name'); 六、同義詞 查看同義詞的名稱SQL>SELECT * FROM user_synonyms; 七、約束條件 查看某表的約束條件SQL>SELECT constraint_name, constraint_type,search_condition, r_constraint_name 2 FROM user_constraints WHERE table_name = UPPER('&table_name'); //注意,表名一定是大寫才行 SQL>SELECT c.constraint_name,c.constraint_type,cc.column_name 2 FROM user_constraints c,user_cons_columns cc 3 WHERE c.owner = upper('&table_owner') 4 AND c.table_name = UPPER('&table_name') 5 AND c.owner = cc.owner and c.constraint_name = cc.constraint_name 6 ORDER BY cc.position; 八、存儲函數(shù)和過程 查看函數(shù)和過程的狀態(tài)SQL>SELECT object_name,status FROM user_objects WHERE object_type='FUNCTION';SQL>SELECT object_name,status FROM user_objects WHERE object_type='PROCEDURE'; 查看函數(shù)和過程的源代碼SQL>SELECT text from all_source WHERE owner=user AND name=UPPER('&plsql_name'); 九、觸發(fā)器 查看觸發(fā)器 SET long 50000; SELECT 'create or replace trigger ' || 本文出自:億恩科技【1tcdy.com】 服務(wù)器租用/服務(wù)器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM] |