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!

RPAD and position starting at +1

vpolasaAug 21 2025

Below query has output:

SELECT rpad(nvl('CA', ' '), 13)||rpad(nvl(to_char(TRUNC(12, 2),'9999.00') , ' '), 13)||rpad(nvl('95670', ' '), 6)     FROM dual UNION ALL
SELECT rpad(nvl('NC', ' '), 13)||rpad(nvl(to_char(TRUNC(238.1, 2),'9999.00') , ' '), 13)||rpad(nvl('27895', ' '), 6)   FROM dual   UNION ALL
SELECT rpad(nvl('MO', ' '), 13)||rpad(nvl(to_char(TRUNC(1938, 2),'9999.00') , ' '), 13)||rpad(nvl('64484', ' '), 6)   FROM dual ;
RPAD(NVL('CA',''),13)||RPAD(NVL
-------------------------------
CA              12.00     95670
NC             238.10     27895
MO            1938.00     64484

I'm trying address 2 issues:

  1. Numbers are starting at position 15 (expected 14)
  2. All numbers should start at position 14

Expected output:

CA           12.00        95670
NC           238.10       27895
MO           1938.00      64484

Working on:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Windows 11 Enterprise

Comments
Post Details
Added on Aug 21 2025
2 comments
84 views