|
|
|
|
|
|
| Author |
Message |
Martin T. *nix forums beginner
Joined: 07 Mar 2005
Posts: 39
|
Posted: Thu Jul 20, 2006 10:53 am Post subject:
to_char number format with optional decimal-point?
|
|
|
Hello all!
Basically, what I want is the following.
Num -> Str
1 -> '1'
10 -> '10'
1.01 -> '1.01'
Is there a possible Number Format Model that will not display the
decimal if there are no decimal digits?
(I know this is the default behaviour of to_char, but I need aditional
formatting, so I need to spec the format model.)
Related to this: Is it possible to specify a number-format model that
will exactly reproduce the to_char default behaviour?
thanks!
best,
Martin |
|
| Back to top |
|
 |
G Quesnel *nix forums addict
Joined: 29 Apr 2005
Posts: 77
|
Posted: Thu Jul 20, 2006 11:51 am Post subject:
Re: to_char number format with optional decimal-point?
|
|
|
I don't have the answer to your question, but if you can not find the
formating string then you could produce the desired result by adding a
case structure around your to_char formatting. Something like ...
SQL> Select (case when 10.01 > trunc(10.01)
2 then trim(trailing '0' from to_char(10.01,'990.999'))
3 else to_char(10.01,'999') end) A_Number
4 from dual;
A_NUMBER
--------
10.01
or perhaps you could wrap the formatted column in two trim statement:
- first to remove trailing '0'
- second, to remove trailing '.'
Hopefully, someone else can come up with a formating string. |
|
| Back to top |
|
 |
Martin T. *nix forums beginner
Joined: 07 Mar 2005
Posts: 39
|
Posted: Fri Jul 21, 2006 7:16 am Post subject:
Re: to_char number format with optional decimal-point?
|
|
|
G Quesnel wrote:
| Quote: | I don't have the answer to your question, but if you can not find the
formating string then you could produce the desired result by adding a
case structure around your to_char formatting. Something like ...
snip
Hopefully, someone else can come up with a formating string.
|
Thanks for your tip! Seems a pretty clean solution.
Let me state something that may spark some more response ...
1.) It is *not* possible with the ORACLE to_char function (in version
9i2) to specify a number format model that will reproduce the default
behaviour of the function w/o format model.
2.) It is, specifically, *not* possible to describe a number format
model such that the decimal-point is not displayed if there are no
decimals and is displayed if there are significant decimals.
Now - I do also *not* claim that this is the absolute truth, but it
(sadly) will remain my truth until someone proves me wrong.
best,
Martin
p.s.: I guess in 10g there would be some really nice solution with a
regexp  |
|
| Back to top |
|
 |
skuzworks@googlemail.com *nix forums beginner
Joined: 21 Jul 2006
Posts: 1
|
Posted: Fri Jul 21, 2006 9:23 am Post subject:
Re: to_char number format with optional decimal-point?
|
|
|
Martin T. wrote:
| Quote: | G Quesnel wrote:
I don't have the answer to your question, but if you can not find the
formating string then you could produce the desired result by adding a
case structure around your to_char formatting. Something like ...
snip
Hopefully, someone else can come up with a formating string.
Thanks for your tip! Seems a pretty clean solution.
Let me state something that may spark some more response ...
1.) It is *not* possible with the ORACLE to_char function (in version
9i2) to specify a number format model that will reproduce the default
behaviour of the function w/o format model.
2.) It is, specifically, *not* possible to describe a number format
model such that the decimal-point is not displayed if there are no
decimals and is displayed if there are significant decimals.
Now - I do also *not* claim that this is the absolute truth, but it
(sadly) will remain my truth until someone proves me wrong.
best,
Martin
p.s.: I guess in 10g there would be some really nice solution with a
regexp
|
Hello,
Just a thought: does CAST solve this problem?
SQL> select cast (1 as varchar(30)) from dual;
CAST(1ASVARCHAR(30))
------------------------------
1
SQL> select cast (100 as varchar2(30)) from dual;
CAST(100ASVARCHAR2(30))
------------------------------
100
SQL> select cast (1.1001 as varchar2(30)) from dual;
CAST(1.1001ASVARCHAR2(30))
------------------------------
1.1001
SQL> select cast (.100 as varchar2(30)) from dual;
CAST(.100ASVARCHAR2(30))
------------------------------
..1
SQL> select cast (1.100 as varchar2(30)) from dual;
CAST(1.100ASVARCHAR2(30))
------------------------------
1.1
SQL> select cast (1.000 as varchar2(30)) from dual;
CAST(1.000ASVARCHAR2(30))
------------------------------
1 |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Sun Nov 23, 2008 1:46 pm | All times are GMT
|
|
Power Rangers | Debt | Internet Advertising | Mobile Phone | Loans
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|