Monday, March 03, 2014

Justify Left, Centre and Right

This was tested on Oracle 11.2. NUMBER items and their column headings are right justified by default:
 
SQL> set numwidth 15
SQL> select count(*) table_count from dba_tables
  2  /
 
    TABLE_COUNT
---------------
           3110
 
SQL>
 
If you want to see the heading in the centre of the column, you can do so with justify centre:
 
SQL> col table_count justify centre
SQL> select count(*) table_count from dba_tables
  2  /
 
  TABLE_COUNT
---------------
           3110
 
SQL>
 
If you want to see the heading to the left of the column, you can do so with justify left:
 
SQL> col table_count justify left
SQL> select count(*) table_count from dba_tables
  2  /
 
TABLE_COUNT
---------------
           3110
 
SQL>
 
VARCHAR2 items and their column headings are left justified by default:
 
SQL> select table_name from dba_tables
  2  where rownum = 1
  3  /
 
TABLE_NAME
------------------------------
CON$
 
SQL>
 
If you want to see the heading in the centre of the column, you can do so with justify centre:
 
SQL> col table_name justify centre
SQL> select table_name from dba_tables
  2  where rownum = 1
  3  /
 
          TABLE_NAME
------------------------------
CON$
 
SQL>
 
If you want to see the heading to the right of the column, you can do so with justify right:
 
SQL> col table_name justify right
SQL> select table_name from dba_tables
  2  where rownum = 1
  3  /
 
                    TABLE_NAME
------------------------------
CON$

2 comments:

  1. Anonymous10:11 pm

    Is there an easy way to LEFT, CENTRE and RIGHT justify the actual values returned rather than the headings?

    ReplyDelete
  2. Dear Anonymous,

    Not as far as I know.
    Funnily enough, when I first looked at this feature, that's exactly what I thought it was going to do!

    Kind Regards,

    Andrew

    ReplyDelete