【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