查詢oracle表的信息

收集的一些oracle信息的查詢

1、查詢出所有的用戶表

select   *   from   user_tables   可以查詢出所有的用戶表
2、查詢出用戶所有表的索引
select   *   from   user_indexes
3、查詢用戶表的索引(非聚集索引):
select   *   from   user_indexes where   uniqueness='NONUNIQUE'
4、查詢用戶表的主鍵(聚集索引):
select   *   from   user_indexes where   uniqueness='UNIQUE'
5、查詢表的索引
select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and
t.table_name='t_config'
6、查詢表的主鍵
select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and
au.constraint_type = 'P' AND cu.table_name = 't_config'
7、查找表的唯一性約束(包括名稱,構成列):
select column_name from user_cons_columns cu, user_constraints au where cu.constraint_name=au.constraint_name and
cu.table_name='t_config'
8、查找表的外鍵
select * from user_constraints c where c.constraint_type = 'R' and c.table_name='t_config'
查詢外鍵約束的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵名稱
查詢引用表的鍵的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵引用表的鍵名
9、查詢表的所有列及其屬性

select t.*,c.COMMENTS from user_tab_columns t,user_col_comments c where t.table_name='t_config'

10、查詢表、視圖、序列、觸發器

select * from user_tables;

select * from user_views;

select * from user_sequences;

select * from user_triggers;

11、實例

select rownum as id,
       to_char(sysdate + rownum / 24 / 3600, 'yyyy-mm-dd hh24:mi:ss') as inc_datetime,
       trunc(dbms_random.value(0, 100)) as random_id,
       dbms_random.string('x', 20) random_string
  from dual
connect by level <= 10000;

1、利用Oracle特有的“connect by”樹形連接語法生成測試記錄,“level <= 10000”表示要生成10000記錄;
2、利用rownum虛擬列生成遞增的整數數據;
3、利用sysdate函數加一些簡單運算來生成日期數據,本例中是每條記錄的時間加1秒;
4、利用dbms_random.value函數生成隨機的數值型數據,本例中是生成0到100之間的隨機整數;
5、利用dbms_random.string函數生成隨機的字符型數據,本例中是生成長度爲20的隨機字符串,字符串中可以包括字符或數字,-- 'u', 'U' - 返回全是大寫的字符串 -- 'l', 'L' - 返回全是小寫的字符串 -- 'a', 'A' - 返回大小寫結合的字符串 -- 'x', 'X' - 返回全是大寫和數字的字符串 -- 'p', 'P' - 返回鍵盤上出現字符的隨機組合


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