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!

format number with mask

muttleychessFeb 20 2020 — edited Feb 21 2020

Hi

I would like to be able to display a string of numbers, with a certain mask, with dots, but the string can come with dots and without dots

Example the string number

'84141000'   or    '8414.10.00'

if it always came with stitches it would only use

select substr(&P_NCM_CODIGO, 1, level) NCM from dual where level in (2, 4, 5, 6, 7, 8, 10,12) connect by level <= length(&P_NCM_CODIGO)

because it can come without a point and with points I'm using the solution below, without dots always, using replace removing dots

  --without points
       SELECT
                      RTRIM(REGEXP_REPLACE(col01,
                                      '(\d{0,4})(\d{0,2})(\d{0,2})(\d{0,2})',
                                      '\1.\2.\3.\4.',
                                      1,
                                      1),
                                     '.') NCM_DESBR
               FROM (SELECT SUBSTR(&P_NCM_CODIGOx, 1, LEVEL) col01,
                           LEVEL AS NIVEL
                    FROM DUAL
                    WHERE LEVEL IN (2, 4, 5, 6, 7, 8, 10)
                  CONNECT BY LEVEL <= LENGTH(&P_NCM_CODIGOx))

Is there any other way to display with dots, the user sending with or without dots?

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

PL/SQL Release 11.2.0.4.0 - Production

CORE    11.2.0.4.0    Production

TNS for Linux: Version 11.2.0.4.0 - Production

NLSRTL Version 11.2.0.4.0 - Production

This post has been answered by mathguy on Feb 20 2020
Jump to Answer
Comments
Post Details
Added on Feb 20 2020
3 comments
428 views