Preventing sqlplus truncation of column names, without individual column formatting

前端 未结 6 2306
感情败类
感情败类 2021-02-09 13:13

By default sqlplus truncates column names to the length of the underlying data type. Many of the column names in our database are prefixed by the table name, and therefore look

6条回答
  •  醉话见心
    2021-02-09 13:33

    I had the same problem trying to implement this feature in VoraX. In the next version I have in mind the following solution:

    set feedback off 
    set serveroutput on
    declare
      l_c number;
      l_col_cnt number;
      l_rec_tab DBMS_SQL.DESC_TAB2;
      l_col_metadata DBMS_SQL.DESC_REC2;
      l_col_num number;
    begin
      l_c := dbms_sql.open_cursor;
      dbms_sql.parse(l_c, '', DBMS_SQL.NATIVE);
      DBMS_SQL.DESCRIBE_COLUMNS2(l_c, l_col_cnt, l_rec_tab);
      for colidx in l_rec_tab.first .. l_rec_tab.last loop
        l_col_metadata := l_rec_tab(colidx);
        dbms_output.put_line('column ' || l_col_metadata.col_name || ' heading ' || l_col_metadata.col_name);
      end loop;
      DBMS_SQL.CLOSE_CURSOR(l_c);
    end;
    

    Instead of tweaking column sizes, formatting and stuff just enforce the column heading with the column name you want. I think the same approach would work also with DBA_TAB_COLUMNS solution but I prefer the DBMS_SQL one as it also considers the aliases and it gets only the columns you query.

    EDIT: Using just "column heading" doesn't work. It's still needed to use "column format" statements. So, please ignore my previous answer.

提交回复
热议问题