Home » Developer & Programmer » Reports & Discoverer » using operators
using operators [message #411502] |
Sat, 04 July 2009 07:17 |
|
hi all,
In one of my reports the values of amount column has to be specified as follows
(+) 32,54,123
(-) 22,55,012
and so on.
the problem i face is if i put the + and - sign within brackets, i am not able to put punctuation in the amount and if i use punctuation i am not able to put the + and - sign within brackets.
Is there a way to get the output of numbers in the same format as mentioned above
narayan
|
|
|
|
|
Re: using operators [message #411646 is a reply to message #411503] |
Mon, 06 July 2009 03:34 |
|
hi,
i used your code and i got the result of + and - within brackets, but the amount does not have punctuation and in the property palette also the format mask does not come to use the punctuation.
the result after using the decode function is like this
amount
(+) 1000
(+) 2000
(-)-500
I dont want the minus sign to repeat again and i also want the numbers to be like this
(+) 1,000
(+) 2,000
(-) 500
could you pl let me know the necessary corrections
lacchhii
|
|
|
|
|
Re: using operators [message #411723 is a reply to message #411680] |
Mon, 06 July 2009 08:03 |
|
hi,
i used the code this way using decode and to_char, but i got the error message "ORA-017222--INVALID NUMBER"
CODE USED
SELECT MJH,
DECODE(SIGN(TO_CHAR(PAMT,'99,99,999')),1,'(+)'||' '||PAMT,-1,'(-)'||' '||ABS(PAMT),PAMT)
I DID TRY WRITING IT THIS WAY ALSO
SELECT MJH,
DECODE(SIGN(TO_CHAR(PAMT,'99,99,999')),1,'(+)'||' '||(TO_CHAR(PAMT,'99,99,999')),-1,'(-)'||' '||ABS((TO_CHAR(PAMT,'99,99,999'))),(TO_CHAR(PAMT,'99,99,999')))
I get the desired result if i use the decode and to_char function seperately.
Kindly help me out and correct the mistake.
lacchhii
|
|
|
Re: using operators [message #411731 is a reply to message #411502] |
Mon, 06 July 2009 08:30 |
cookiemonster
Messages: 13962 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Sign accepts numbers as arguments, not chars.
You need to to_char the bits that are going to be displayed, nothing else.
Lose the first to_char.
|
|
|
Re: using operators [message #411761 is a reply to message #411723] |
Mon, 06 July 2009 10:59 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
Here's how it goes: as Cookiemonster has said, SIGN function accepts numbers:SQL> select sign(123456) from dual;
SIGN(123456)
------------
1
In order to convert number to a character with desired format, we use TO_CHAR function:SQL> select to_char(123456, '999,999') from dual;
TO_CHAR(
--------
123,456
So far, so good.
Now let's try to apply SIGN to this character:SQL> select sign(to_char(123456, '999,999')) from dual;
select sign(to_char(123456, '999,999')) from dual
*
ERROR at line 1:
ORA-01722: invalid number Nope, won't work. It is the same asSQL> select sign('123,456') from dual;
select sign('123,456') from dual
*
ERROR at line 1:
ORA-01722: invalid number which is - as we are talking about strings - the same asSQL> select sign('abcd') from dual;
select sign('abcd') from dual
*
ERROR at line 1:
ORA-01722: invalid number
Do you understand it now? You can't determine SIGN of a string!
|
|
|
Goto Forum:
Current Time: Thu Jan 23 15:47:30 CST 2025
|