The TO_CHAR function converts a number or date to a varchar2.
To_char syntax
TO_CHAR( value, [ format_mask ], [ nls_param ] )
To_char example
select to_char(2015.82, '9999.99') from dual;
Result: 2015.82
select to_char(2015.82, '9999.999') from dual;
Result: 2015.820
select to_char(2015.82, '$9,999.00') from dual;
Result: $2,015.82
select to_char(sysdate, 'yyyy/mm/dd') from dual;
Result: 2014/12/26
select to_char(sysdate, 'MON DDth, YYYY') from dual;
Result: DEC 26TH, 2014
select to_char(sysdate, 'yyyy') from dual;
Result: 2014
To_char example
STUDENT_ID |
FIRST_NAME |
LAST_NAME |
CITY |
1 |
Daniel |
SCOTT |
New York |
2 |
Anthony |
SIMMONS |
Chicago |
3 |
Sophia |
THOMPSON |
Los Angeles |
select s.STUDENT_ID, s.FIRST_NAME, s.LAST_NAME, s.CITY
from STUDENTS s
where TO_CHAR(s.STUDENT_ID)='2';
STUDENT_ID |
FIRST_NAME |
LAST_NAME |
CITY |
2 |
Anthony |
SIMMONS |
Chicago |