Using to_char to format currency?

4002 views sql
2

So I want the salary returned in the result set to be formatted to this currency type but I believe I am using the to_char in the wrong spot but I'm not sure how. I'm also not sure if I have to use it in both instances of Salary either. Any help would be much appreciated!!

SELECT EMPNO, ENAME, JOB, SAL * 52 TO_CHAR('$999,999')
FROM EMP
WHERE SAL * 52 >
(SELECT AVG(SAL *52) FROM EMP);

I receive the
ORA-00923: FROM keyword not found where expected error from Oracle Apex.

It runs fine without the to_char.

answered question

3 Answers

6

you can try to let your value in first parameter second is your format.

SELECT EMPNO, ENAME, JOB, to_char(SAL * 52,'$999,999')
FROM EMP
WHERE SAL*52 > (SELECT AVG(SAL * 52) FROM EMP) ;

posted this
13

Are you looking for this:

SELECT EMPNO, ENAME, JOB, TO_CHAR(SAL * 52, 'FM999,999') as SALVAL 
FROM EMP
WHERE SAL * 52 >
(SELECT AVG(SAL *52) FROM EMP);

posted this
8

You need to pass the data you want formatting into to_char also:

SELECT TO_CHAR(123, '$999,999') from dual

So pass your sal*52 in as the first argument

posted this

Have an answer?

JD

Please login first before posting an answer.