Oracle資料字典使用入門

來源:互聯網
上載者:User

下面按類別列出一些Oracle使用者常用資料字典的查詢使用方法。

一、使用者

查看目前使用者的預設資料表空間

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;

查看名稱包含log字元的表

SQL>SELECT object_name,object_id FROM user_objects WHERE INSTRobject_name,'LOG')>0;

查看某表的建立時間

SQL>SELECT object_name,created FROM user_objects WHERE object_name=UPPER'&table_name');

查看某表的大小

SQL>SELECT SUMbytes)/1024*1024) AS sizeM)

FROM user_segments WHERE segment_name=UPPER'&table_name');

查看放在ORACLE的記憶體區裡的表

SQL>SELECT table_name,cache FROM user_tables WHERE INSTRcache,'Y')>0;

三、索引

查看索引個數和類別

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 SUMbytes)/1024*1024)AS sizeM)

FROM user_segments WHERE segment_name=UPPER'&index_name');

四、序號

查看序號,last_number是當前值

SQL>SELECT * FROM user_sequences;

五、視圖

查看視圖的名稱

SQL>SELECT view_name FROM user_views;

查看建立視圖的select語句

SQL>SELECT 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');

六、同義字

查看同義字的名稱

SQL>SELECT * FROM user_synonyms;

七、約束條件

查看某表的約束條件

SQL>SELECT constraint_name, constraint_type,search_condition, r_constraint_nameFROM user_constraints WHERE table_name = UPPER'&table_name');//注意,表名一定是大寫才行SQL>SELECT c.constraint_name,c.constraint_type,cc.column_nameFROM user_constraints c,user_cons_columns ccWHERE c.owner = upper'&table_owner')AND c.table_name = UPPER'&table_name')AND c.owner = cc.owner and c.constraint_name = cc.constraint_name 6 ORDER BY cc.position;

八、儲存函數和過程

查看函數和過程的狀態

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');

九、觸發器

查看觸發器

SET long 50000;SET heading off;SET pagesize 2000;SELECT'create or replace trigger ' ||trigger_name || '' || chr(10)||DECODE( SUBSTR( trigger_type, 1, 1 ),'A', 'AFTER', 'B', 'BEFORE', 'I', 'INSTEAD OF' ) ||chr(10) ||triggering_event || chr(10) ||'ON ' || table_owner || '.' ||table_name || '' || chr(10) ||DECODE( instr( trigger_type, 'EACH ROW' ), 0, null,'FOR EACH ROW' ) || chr(10) ,trigger_bodyFROM user_triggers;
  1. 解析Oracle 11g閃回資料歸檔新功能
  2. 給Oracle進行健康體檢
  3. Oracle 11g新特性與應用詳解

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.