獲取表字段:
select * from user_tab_columns where Table_Name='用戶表' order by column_name
獲取表注釋:
select * from user_tab_comments where Table_Name='用戶表' order by Table_Name
獲取字段注釋:
select * from user_col_comments where Table_Name='用戶表' order by column_name /* 獲取表:*/ select table_name from user_tables; //當前用戶的表 select table_name from all_tables; //所有用戶的表 select table_name from dba_tables; //包括系統表 select table_name from dba_tables where owner='zfxfzb' /* user_tables: table_name,tablespace_name,last_analyzed等 dba_tables: ower,table_name,tablespace_name,last_analyzed等 all_tables: ower,table_name,tablespace_name,last_analyzed等 all_objects: ower,object_name,subobject_name,object_id,created,last_ddl_time,timestamp,status等 */ /* 獲取表字段:*/ select * from user_tab_columns where Table_Name='用戶表'; select * from all_tab_columns where Table_Name='用戶表'; select * from dba_tab_columns where Table_Name='用戶表'; /* user_tab_columns: table_name,column_name,data_type,data_length,data_precision,data_scale,nullable,column_id等 all_tab_columns : ower,table_name,column_name,data_type,data_length,data_precision,data_scale,nullable,column_id等 dba_tab_columns: ower,table_name,column_name,data_type,data_length,data_precision,data_scale,nullable,column_id等 */ /* 獲取表注釋:*/ select * from user_tab_comments /* user_tab_comments:table_name,table_type,comments 相應的還有dba_tab_comments,all_tab_comments,這兩個比user_tab_comments多了ower列。 */ /* 獲取字段注釋:*/ select * from user_col_comments /* user_col_comments:table_name,column_name,comments 相應的還有dba_col_comments,all_col_comments,這兩個比user_col_comments多了ower列。 */
Oracle 下讀取表/字段的備注信息
Oracle 通過COMMENT ON TABLE / COMMENT ON COLUMN 追加表/字段的備注。
CREATE TABLE "MR_DEPT" (
"DEPT_ID" NUMBER NOT NULL ,
"PARENT_ID" NUMBER,
"DEPT_NAME" CHAR(20) NOT NULL ,
"STATUS" NUMBER DEFAULT 1 NOT NULL ,
PRIMARY KEY ("DEPT_ID")
);
COMMENT ON TABLE "MR_DEPT" IS '部門表';
COMMENT ON COLUMN "MR_DEPT"."DEPT_ID" IS '部門編號';
COMMENT ON COLUMN "MR_DEPT"."PARENT_ID" IS '上級部門編號';
COMMENT ON COLUMN "MR_DEPT"."DEPT_NAME" IS '部門名';
COMMENT ON COLUMN "MR_DEPT"."STATUS" IS '狀態';
備注加好以後,如何在查詢中檢索呢?
查詢表的備注信息
SELECT
TABLE_NAME,
TABLE_TYPE,
COMMENTS
FROM
USER_TAB_COMMENTS
WHERE
TABLE_NAME = 'MR_DEPT;
查詢字段的備注信息
SELECT
TABLE_NAME,
COLUMN_NAME,
COMMENTS
FROM
USER_COL_COMMENTS
WHERE
TABLE_NAME = 'MR_DEPT;
參考資料:hi.baidu.com/...c.html
樓主可以使用下面的語句:
SELECT b.column_name column_name --字段名
,b.data_type data_type --字段類型
,b.data_length --字段長度
,a.comments comments --字段注釋
FROM user_col_comments a
,all_tab_columns b
WHERE a.table_name = b.table_name and
a.table_name = 'table_name';
PS:
table_name 大小寫敏感。