ORACLE 查看當前用戶信息(用戶,表視圖,索引,表空間,同義詞,存儲過程,約束條件)

  1. 一、用戶   
  2.   查看當前用戶的缺省表空間  
  3.   
  4.   SQL>select username,default_tablespace from user_users;  
  5.   
  6.   查看當前用戶的角色  
  7.   
  8.   SQL>select * from user_role_privs;  
  9.   
  10.   查看當前用戶的系統權限和表級權限  
  11.   
  12.   SQL>select * from user_sys_privs;  
  13.   
  14.   SQL>select * from user_tab_privs;  
  15.   
  16.   顯示當前會話所具備的權限  
  17.   
  18.   SQL>select * from session_privs;  
  19.   
  20.   顯示指定用戶所具備的系統權限  
  21.   
  22.   SQL>select * from dba_sys_privs where grantee='GAME';  
  23.   
  24.   二、表  
  25.   
  26.   查看用戶下全部的表  
  27.   
  28.   SQL>select * from user_tables;  
  29.   
  30. SELECT * FROM ALL_TABLES;  
  31.   
  32.   查看名稱包含log字符的表  
  33.   
  34.   SQL>select object_name,object_id from user_objects  
  35.   
  36.   where instr(object_name,'LOG')>0;  
  37.   
  38.   查看某表的建立時間  
  39.   
  40.   SQL>select object_name,created from user_objects where object_name=upper('&table_name');  
  41.   
  42.   查看某表的大小  
  43.   
  44.   SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments  
  45.   
  46.   where segment_name=upper('&table_name');  
  47.   
  48.   查看放在ORACLE的內存區裏的表  
  49.   
  50.   SQL>select table_name,cache from user_tables where instr(cache,'Y')>0;  
  51.   
  52.   三、索引  
  53.   
  54.   查看索引個數和類別  
  55.   
  56.   SQL>select index_name,index_type,table_name from user_indexes order by table_name;  
  57.   
  58.   查看索引被索引的字段  
  59.   
  60.   SQL>select * from user_ind_columns where index_name=upper('&index_name');  
  61.   
  62.   查看索引的大小  
  63.   
  64.   SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments  
  65.   
  66.   where segment_name=upper('&index_name');  
  67.   
  68.   四、序列號  
  69.   
  70.   查看序列號,last_number是當前值  
  71.   
  72.   SQL>select * from user_sequences;  
  73.   
  74.   五、視圖  
  75.   
  76.   查看視圖的名稱  
  77.   
  78.   SQL>select view_name from user_views;  
  79.   
  80.   查看建立視圖的select語句  
  81.   
  82.   SQL>set view_name,text_length from user_views;  
  83.   
  84.   SQL>set long 2000; 說明:能夠根據視圖的text_length值設定set long 的大小  
  85.   
  86.   SQL>select text from user_views where view_name=upper('&view_name');  
  87.   
  88.   六、同義詞  
  89.   
  90.   查看同義詞的名稱  
  91.   
  92.   SQL>select * from user_synonyms;  
  93.   
  94. SELECT * FROM ALL_SYSNONYMS;  
  95.   
  96.   七、約束條件  
  97.   
  98.   查看某表的約束條件  
  99.   
  100.   SQL>select constraint_name, constraint_type,search_condition, r_constraint_name  
  101.   
  102.   from user_constraints where table_name = upper('&table_name');  
  103.   
  104.   SQL>select c.constraint_name,c.constraint_type,cc.column_name  
  105.   
  106.   from user_constraints c,user_cons_columns cc  
  107.   
  108.   where c.owner = upper('&table_owner') and c.table_name = upper('&table_name')  
  109.   
  110.   and c.owner = cc.owner and c.constraint_name = cc.constraint_name  
  111.   
  112.   order by cc.position;  
  113.   
  114.   八、存儲函數和過程  
  115.   
  116.   查看函數和過程的狀態  
  117.   
  118.   SQL>select object_name,status from user_objects where object_type='FUNCTION';  
  119.   
  120.   SQL>select object_name,status from user_objects where object_type='PROCEDURE';  
  121.   
  122.   查看函數和過程的源代碼  
  123.   
  124.   SQL>select text from all_source where owner=user and name=upper('&plsql_name');  
相關文章
相關標籤/搜索