Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

SQLPLUS Formatting

Options
  • 08-02-2008 1:45am
    #1
    Registered Users Posts: 401 ✭✭


    Hi Guys,

    I have what seems like a simple problem that has been driving me crazy for hours.

    In a nutshell, is it possible to choose the alignment of the data outputted by SQLPLUS?

    I know it defaults to right-justify for numeric columns and left-justify for text. I am looking for a way to override this and centre the data of some of columns.

    The justify command appears to only affect the column header and not the data itself.

    Any help very much appreciated.

    Cheers,

    Jules


Comments

  • Moderators, Politics Moderators Posts: 39,585 Mod ✭✭✭✭Seth Brundle


    isn't it something like
    column column_name justify left
    or
    column column_name justify right
    or
    column column_name justify center

    Its a year or two now since I played with Oracle!

    Edit: just re-reading your post - was this the command you used which resulted in just the heading changing?


  • Registered Users Posts: 401 ✭✭Julesie


    Yup afraid so...

    I have looked it up in a couple of reference manuals and it seems the Justify command is only meant to affect the header.


  • Moderators, Politics Moderators Posts: 39,585 Mod ✭✭✭✭Seth Brundle


    Why do you want to align it in SQL PLus anyway as its not really a reporting tool?


  • Registered Users Posts: 401 ✭✭Julesie


    I know...believe me i'd love to be using something more suitable. However the powers that be won't shell out for any such luxury so I am stuck trying to make the most of the available resources.

    To be honest the alignment isn't absolutely critical it was more that it is bugging me that i can't find a way to override the default formatting.

    I still think there must be a way.


  • Registered Users Posts: 23,212 ✭✭✭✭Tom Dunne


    Off the top of my head, I don't know.

    But have a look here, you may find something :SQL*Plus quick reference


  • Advertisement
  • Moderators, Politics Moderators Posts: 39,585 Mod ✭✭✭✭Seth Brundle




  • Registered Users Posts: 2 ste_wood


    Julesie wrote: »
    Hi Guys,

    I have what seems like a simple problem that has been driving me crazy for hours.

    In a nutshell, is it possible to choose the alignment of the data outputted by SQLPLUS?

    I know it defaults to right-justify for numeric columns and left-justify for text. I am looking for a way to override this and centre the data of some of columns.

    The justify command appears to only affect the column header and not the data itself.

    Any help very much appreciated.

    Cheers,

    Jules

    I know this post is very old but to provide a useful reply to all the googlers out there this is how you do this. I'm also aware that a to_number inside a to_char is bonkers but it demonstrates that the to_char is effecting an actual number not a char string made up of numbers. With rpad you need to be careful that the value you specify is big enough for the field so use the to_char method if the numbers are very large and vary alot.

    SQL> select rpad(to_number(123456789),5,' ') AS TEST1 from dual;
    TEST1
    12345
    SQL> select to_char(to_number(123456789)) AS TEST2 from dual;
    TEST2
    123456789


  • Registered Users Posts: 2 ste_wood


    And another way..

    SQL> select ltrim(to_number(123456789)) from dual;
    LTRIM(TO_
    123456789


Advertisement