【Oracle sql】用sql獲取表中字段、表注釋和列注釋


建表語句:

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


免責聲明!

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



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