views:

2940

answers:

3

Hi, I'm working on a query which returns numeric values (currency). Some of the values are whole numbers and are being displayed as 3, 5, 2 etc whilst other numbers are coming up like 2.52, 4.50 etc.

How can I force oracle to always show the decimal places?

Thanks

+5  A: 

The display and formatting of the data should be handled at the presentation layer - not the data one.

Use the facilities provided by your front end to format the values as you see fit.

no_one
What if Oracle *is* the presentation layer? e.g. the MODPLSQL toolkit?
cagcowboy
or a simple report in SQL*Plus?
cagcowboy
wasn't really clear from the question :-).
no_one
+4  A: 
TO_CHAR(pAmount, '9,999,999.99');

http://www.techonthenet.com/oracle/functions/to_char.php

http://www.ss64.com/orasyntax/to_char.html

cagcowboy
Thanks. Can this also be used to add zeros to numbers that are less than 1? eg 0.52 instead of .52?
From the top of my head use TO_CHAR(pAmount, '9,999,990.99');
cagcowboy
A: 

In SQL*Plus you can use the COLUMN directive to specify formatting on a per-column basis, separate from the query itself. That way you keep your query "clean" for possible other uses and still get your formatting. (In SQL*Plus at least...)

e.g

COLUMN SAL FORMAT 99,990.99

Google for "SQL*Plus User's Guide and Reference" and you should get links to the Oracle location for your Oracle version. 10.1 is here if that'll do. They'll probably all be about the same, mind you: I don't think SQL*Plus has changed much since I learned it in 1988 on Oracle 5.1.17...

Mike Woodhouse