实际开发时我们经常需要将一个表的数据以excel的形式导出,导出时列头需要用别名,这时如果建表时添加了备注我们可以通过一句sql语句将sql字符串输出:
select wmsys.wm_concat(ss) from (select 'a.'||tc.COLUMN_NAME||' '||cc.comments ss from user_tab_columns tc
left join user_col_comments cc on cc.table_name = tc.TABLE_NAME and cc.column_name = tc.COLUMN_NAME
where tc.Table_Name=UPPER('表名') order by tc.column_id asc)t
其中UPPER函数内填你需要输出的表名,user_tab_columns /user_col_comments 为Oracle自带的系统视图分别用于存放所有表字段的信息及字段备注信息。