Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 
 

Formatting numbers in Oracle SQL

Oracle Database Tips by Donald BurlesonJuly 7, 2015


Question:  I'm having a problem displaying a NUMBER column type for display purposes.

I want the plus and minus number notation to appear within brackets, along with punctuation like this

(+) 1000,00,000
(-) 2,00,000


The SQL I used is below, but I get the error "ORA-017222 -- Invalid number" when I try to format the number column using to_char:

select
   mjh,
   decode(sign(to_char(pamt,'99,99,999')),1,'(+)'||' '||pamt,-1,'(-)'||' '||pamt,pamt)
from
   kfa_01;

How do I format number columns in Oracle SQL?

Answer:  If the SQL runs inside SQL*Plus it's easy to format numbers using column (col) directive in SQL*Plus. 

In standard SQL you can also use built-in function to format numbers, but number formatting is less straightforward.  Oracle guru Laurent Schneider (author of the popular book Advanced SQL Programming) offers this solution to number formatting in SQL:

SELECT
  column_value,
  REPLACE (
    REPLACE (
      TO_CHAR (column_value, 'FMS9999,99,9999'),
      '-', '(-) '
    ),
    '+', '(+) '
  ) fmt
FROM TABLE(sys.odcinumberlist(1,-1e7 / 7));

COLUMN_VALUE FMT                
------------ --------------------
           1 (+) 1              
  -1428571.4 (-) 1,42,8571


As we see, you can use the replace and to_char SQL functions to format numeric columns for attractive display in native Oracle SQL.


 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.