建表語句:
create table test02( id number(3), name nvarchar2(20), age number(3), primary key(id) ); COMMENT ON TABLE test02 IS '測試表'; COMMENT ON COLUMN test02.id IS 'ID'; COMMENT ON COLUMN test02.name IS '名字'; COMMENT ON COLUMN test02.age IS '年齡';
獲取表中字段名:
select column_name from user_tab_columns where table_Name=upper('test02');
獲取表注釋:
select comments from user_tab_comments where table_Name=upper('test02');
獲取列名和列注釋:
select column_name,comments from user_col_comments where table_Name=upper('test02');
執行效果:
SQL> select column_name from user_tab_columns where table_Name=upper('test02'); COLUMN_NAME ------------------------------ ID NAME AGE SQL> SQL> select comments from user_tab_comments where table_Name=upper('test02'); COMMENTS ------------------------------ 測試表 SQL> SQL> select column_name,comments from user_col_comments where table_Name=upper('test02'); COLUMN_NAME COMMENTS ------------------------------ ------------------------------ ID ID NAME 名字 AGE 年齡 SQL>
END