Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Format columns of data with variable size having numbers and alphabet in a SQL query

Alex12345Jan 12 2024

Hi All,

I am trying to use combined query outputs as a single value for a tree/shuttle . However when I format multiple columns and trying to format these column values at a fixed place because of numbers/alphabets the output displays not correctly.

I tried using substr, pad, cast , convert and none of them seems to be working.

Here is my sql query

WITH MY_DATA AS

(SELECT 'RAJ00PD1ZFPDEFAULT' VAL FROM DUAL
UNION
SELECT 'RAJI0PD1ZFPDEFAULT' VAL FROM DUAL
)

SELECT SUBSTR (VAL, 1, 6)|| SUBSTR (VAL, 7, 4) COMB, SUBSTR (VAL, 1, 6) A, SUBSTR (VAL, 7, 4) B, VAL FROM MY_DATA ;

RAJ00PD1ZF RAJ00P D1ZF RAJ00PD1ZFPDEFAULT
RAJI0PD1ZF RAJI0P D1ZF RAJI0PD1ZFPDEFAULT

Since the space occupied by I is less than 0, the overall output formatting is off by one character.

This gets very ugly when I use these values in a tree or a shuttle with multiple records.

Thank you

Best Regards

Alex

Comments
Post Details
Added on Jan 12 2024
7 comments
133 views