This discussion is archived
5 Replies Latest reply: Jan 4, 2013 11:02 AM by EdStevens RSS

String Justifications

969952 Newbie
Currently Being Moderated
Hi All,

Can any one please let me know , as per my understanding NUMBER/DATE values are RIGHT justified and Character types are Left justified. Correct me if am wrong.

But I want to keep it in CENTER Justified . ( if I use LPAD or RPAD I must give the string length .. but I am not sure about the string length) Is it possible? If possible please let me know the process for this?

Thanks.

Edited by: 966949 on Jan 4, 2013 9:38 AM
  • 1. Re: String Justifications
    sb92075 Guru
    Currently Being Moderated
    966949 wrote:
    Hi All,

    Can any one please let me know , as per my understanding NUMBER/DATE values are RIGHT justified and Character types are Left justified. Correct me if am wrong.

    But I want to keep it in CENTER Justified. Is it possible?
    no
  • 2. Re: String Justifications
    Frank Kulash Guru
    Currently Being Moderated
    Hi,
    966949 wrote:
    Hi All,

    Can any one please let me know , as per my understanding NUMBER/DATE values are RIGHT justified and Character types are Left justified. Correct me if am wrong.
    DATEs are left-justified; otherwise, that's right, at least in SQL*Plus.
    But I want to keep it in CENTER Justified. Is it possible? If possible please let me know the process for this?
    For strings, you have to use LPAD, as you feared.
    For numbers, convert to a string and use LPAD.

    There is a tantalyzing SQL*Plus command "COLUMN ... JUSTIFY CENTER", but it only aligns the heading, not the data.

    For example:
    COLUMN     job15     FORMAT     A15     JUSTIFY CENTER
    
    SELECT     ename
    ,     LPAD ( ' '
              , (15 - LENGTH (job)) / 2
              ) || job        AS job15
    FROM    scott.emp
    ;
    Output:
    ENAME           JOB15
    ---------- ---------------
    SMITH           CLERK
    ALLEN         SALESMAN
    WARD          SALESMAN
    JONES          MANAGER
    MARTIN        SALESMAN
    BLAKE          MANAGER
    CLARK          MANAGER
    SCOTT          ANALYST
    KING          PRESIDENT
    TURNER        SALESMAN
    ADAMS           CLERK
    JAMES           CLERK
    FORD           ANALYST
    MILLER          CLERK
    Edited by: Frank Kulash on Jan 4, 2013 12:53 PM
    Added query
  • 3. Re: String Justifications
    EdStevens Guru
    Currently Being Moderated
    966949 wrote:
    Hi All,

    Can any one please let me know , as per my understanding NUMBER/DATE values are RIGHT justified and Character types are Left justified. Correct me if am wrong.
    It is entirely a function of the tool you are using to present the data.

    What tool are you using?

    But I want to keep it in CENTER Justified . ( if I use LPAD or RPAD I must give the string length .. but I am not sure about the string length) Is it possible? If possible please let me know the process for this?

    Thanks.

    Edited by: 966949 on Jan 4, 2013 9:38 AM
  • 4. Re: String Justifications
    969952 Newbie
    Currently Being Moderated
    Am using SQL Developer.
  • 5. Re: String Justifications
    EdStevens Guru
    Currently Being Moderated
    966949 wrote:
    Am using SQL Developer.
    Then your question would be better addressed in the SQL Developer forum: SQL Developer (Not for general SQL/PLSQL questions)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points