Oracle查詢一個命名空間下所有表和視圖的表名、字段名、字段類型、字段大小,是否可為NULL,主鍵和注釋信息


使用SQL查詢Oracle一個命名空間下所有表和視圖的表名、字段名、字段類型、字段大小,是否可為NULL,主鍵和注釋信息。

SQL如下,注意需要將'CDFLOOD'更換為您要查詢的命名空間:

select 
user_tab_cols.table_name 表名,
user_tab_cols.column_name 字段名,
user_tab_cols.data_type 類型,
user_tab_cols.data_length 大小,
user_tab_cols.nullable 是否可為NULL,
CASE
WHEN tpk.COLUMN_NAME  = user_tab_cols.column_name THEN 'Y'  
ELSE 'N' END 是否主鍵,
user_col_comments.COMMENTS 含意
from user_tab_cols
left join (
-- 查詢各表主鍵字段名稱
select table_info.TABLE_NAME,dba_cons_columns.COLUMN_NAME from (
select table_name from user_tab_cols group by table_name order by table_name) table_info
left join dba_constraints on table_info.TABLE_NAME = dba_constraints.TABLE_NAME and dba_constraints.owner='CDFLOOD' and dba_constraints.constraint_type = 'P'
left join dba_cons_columns on dba_constraints.CONSTRAINT_NAME = dba_cons_columns.CONSTRAINT_NAME and dba_constraints.TABLE_NAME = dba_cons_columns.TABLE_NAME and dba_constraints.owner='CDFLOOD' order by TABLE_NAME) tpk on tpk.TABLE_NAME = user_tab_cols.table_name and tpk.COLUMN_NAME = user_tab_cols.column_name
-- 查詢字段注釋
left join user_col_comments on user_col_comments.TABLE_NAME = user_tab_cols.table_name and user_col_comments.COLUMN_NAME = user_tab_cols.column_name
order by user_tab_cols.table_name,user_tab_cols.column_id;

查詢結果如下(值中,'Y'表示是,'N'表示否):


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM