【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

相关