Oracle number format
Hai,
I have a problem with format.i'm number using oracle. I have a numeric field in a database. But when I return it I have to be treated as a floating point number For example: while retreiveing, now I got the result as 200 DR (DR for Debit, it is given manually). Now I need to get the result as 200.00 DR as a result. How can I solve this? Can anyone help me?
source to share
Debit availability implies the need to obtain a loan. In Oracle SQL, we can use the SIGN () function to determine if a number is positive or negative ...
SQL> select to_char(abs(amt), 'fm999g999d00')||' '
2 ||case when sign(amt) = -1 then 'DR' else 'CR' end as fmt_amt
3 from transactions
4 order by txn_ts, txn_id
5 /
FMT_AMT
--------------
200.00 CR
200.00 DR
788.67 CR
788.67 DR
SQL>
source to share
The answers here that suggest TO_CHAR are correct, but if you call this SQL from your application code:
Get the number without formatting it with SQL and then use your programming language to format it. For example, in Java, use the DecimalFormat class. In other words, leave the formatting for specific application code, not SQL.
source to share