Home » SQL & PL/SQL » SQL & PL/SQL » print "+" when using to_char (oracle 12c r1)
print "+" when using to_char [message #683492] Sun, 24 January 2021 12:23 Go to next message
robh0502
Messages: 4
Registered: January 2015
Location: Phoenix, AZ
Junior Member
Hi,
Looking for a way to format a number by showing 0's to the left and right of the decimal. Also, looking to print a plus sign. There should be 6 digits in the front and 6 in the back of the decimal. For example,

654.89 should be displayed as +000654.890000

I've come up with the following

replace(to_char(654.89, '000000.000000'), ' ', '+')

Does anyone have a way to showing the plus sign without using replace?
Re: print "+" when using to_char [message #683499 is a reply to message #683492] Sun, 24 January 2021 13:49 Go to previous messageGo to next message
Michel Cadot
Messages: 67769
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You're close:
SQL> select to_char(654.89, 'S000000.000000') from dual;
TO_CHAR(654.89
--------------
+000654.890000
Re: print "+" when using to_char [message #683500 is a reply to message #683499] Sun, 24 January 2021 13:59 Go to previous messageGo to next message
robh0502
Messages: 4
Registered: January 2015
Location: Phoenix, AZ
Junior Member
Thanks!
Re: print "+" when using to_char [message #683508 is a reply to message #683500] Mon, 25 January 2021 05:19 Go to previous message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
you might want to review the format masks for to_char. There is a lot you can do with them
Previous Topic: Regex Help
Next Topic: logic sql or plsql (merged)
Goto Forum:
  


Current Time: Sun Mar 07 17:52:57 CST 2021